Tuesday, October 21, 2014

Missing spring boot maven dependencies,spring boot maven exception,Spring boot maven error

Add this lines to the spring-boot's pom.xml

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.1.2</version>
        </dependency>

Thursday, October 9, 2014

Spring Examples & Logging Exceptions

Add the lovely missing dependency to pom.xml for the below exception while dealing with Spring Examples

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.9</version>
            <scope>runtime</scope>
        </dependency>

Regards!


C:\Users\ssunel\Downloads\gs-consuming-rest-master\gs-consuming-rest-master\complete>java -jar target\gs-consuming-rest-0.1.0.jar
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:129)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:302)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276)
        at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
        at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
        at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:274)
        at org.springframework.http.client.support.HttpAccessor.<init>(HttpAccessor.java:47)
        at org.springframework.http.client.support.InterceptingHttpAccessor.<init>(InterceptingHttpAccessor.java:35)
        at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:154)
        at hello.Application.main(Application.java:8)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:168)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 17 more
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:129)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:302)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276)
        at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
        at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
        at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:274)
        at org.springframework.http.client.support.HttpAccessor.<init>(HttpAccessor.java:47)
        at org.springframework.http.client.support.InterceptingHttpAccessor.<init>(InterceptingHttpAccessor.java:35)
        at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:154)
        at hello.Application.main(Application.java:8)
        ... 6 more
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:168)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 17 more

Sunday, December 15, 2013

Connect to remote db with SQLPLUS

sqlplus usernamee/passwordd@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=123.123.123.123)(PORT=1521)))(CONNECT_DATA=(SID=MY_REMOTE_DB_SID)))'

sqlplus usernamee/passwordd@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=123.123.123.123)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=MY_REMOTE_DB_SERVICE_NAME)))'

Tuesday, December 10, 2013

MongoDB export import example

EXPORT EXAMPLE

root@ubuntu:/var# mongodump --db test
connected to: 127.0.0.1
DATABASE: test to dump/test
test.system.indexes to dump/test/system.indexes.bson
7 objects
test.profiles to dump/test/profiles.bson
8 objects
test.fs.chunks to dump/test/fs.chunks.bson
3 objects
test.fs.files to dump/test/fs.files.bson
3 objects
test.mys to dump/test/mys.bson
1 objects
test.myContents to dump/test/myContents.bson
95 objects
test.yourContents to dump/test/yourContents.bson
23 objects


IMPORT EXAMPLE

root@ubuntu:/var# mongorestore --db test dump/test
connected to: 127.0.0.1
dump/test/system.indexes.bson
going into namespace [test.system.indexes]
7 objects
dump/test/yourContents.bson
going into namespace [test.yourContents]
23 objects
dump/test/fs.files.bson
going into namespace [test.fs.files]
3 objects
dump/test/myContents.bson
going into namespace [test.myContents]
95 objects
dump/test/fs.chunks.bson
going into namespace [test.fs.chunks]
3 objects
dump/test/profiles.bson
going into namespace [test.profiles]
8 objects
dump/test/mys.bson
going into namespace [test.mys]
1 objects
root@ubuntu:/var#

Friday, July 13, 2012

Where is my cached object ? SpyMemcached client & Memcached example

A simple example which uses spymemcached client against to the memcache server.
Memcached test scenario-1


Install multiple memcache server on the different servers : 127.0.0.1 and 172.28.138.184.
Create a client using these hosts and cache some object with a timeout.
Then check whether is your object cached in server 1 or server 2 ??

Installation guide for ubuntu 
Download spymemcached from here .

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import net.spy.memcached.MemcachedClient;

public class TestScenario1 {

public static void main(String[] args) {
@SuppressWarnings("unchecked")
//compose all servers list
List<InetSocketAddress> allServers = new ArrayList<InetSocketAddress> ();
allServers.add(new InetSocketAddress("127.0.0.1", 11211));//server1 installed on localhost
allServers.add(new InetSocketAddress("172.28.138.184", 11211));// this is server 2 installed on another host


try {
//create a connection against to the all servers
final MemcachedClient memcacheClient2AllServers = createMemcacheClient(allServers);
//create an object and tell memcache to cache it on one of the servers which are given as a list
cacheAnObject(memcacheClient2AllServers);
// now we dont know where the object is actually cached ?? In server 1 or in server 2
// so i will check them in parellel with different threads

//create a connection against to the fist server only
final MemcachedClient memcacheClient2FirstServer = createMemcacheClient(allServers.subList(0, 1));
//create a connection against to the fist second server only
final MemcachedClient memcacheClient2SecondServer = createMemcacheClient(allServers.subList(1, 2));

//Check the cache from all clients by different threads
Thread thread4AllServers = createMemCacheCheckThread(memcacheClient2AllServers,"[1 & 2]");
Thread thread4FirstServerOnly = createMemCacheCheckThread(memcacheClient2FirstServer,"[1]");
Thread thread4SecondServerOnly = createMemCacheCheckThread(memcacheClient2SecondServer,"[2]");

thread4AllServers.start();
thread4FirstServerOnly.start();
thread4SecondServerOnly.start();

thread4AllServers.join();
thread4FirstServerOnly.join();
thread4SecondServerOnly.join();

} catch (Exception e) {
e.printStackTrace();
}
}

private static MemcachedClient createMemcacheClient(List<InetSocketAddress> allServers) throws IOException {
final MemcachedClient memcacheClient2AllServers = new MemcachedClient(allServers); ;
return memcacheClient2AllServers;
}

private static void cacheAnObject(final MemcachedClient memcacheClient2AllServers) {
SomeObject someObject = new SomeObject();
someObject.someField = "serkan sunel";
memcacheClient2AllServers.set("someKey", 60, someObject);
}

private static Thread createMemCacheCheckThread(final MemcachedClient memcacheClient, final String threadName) {
Thread thread = new Thread(){
@Override
public void run() {
while (true) {
try {
checkCache();
sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
private void checkCache() {

SomeObject myObject=null;
Future<Object> f=memcacheClient.asyncGet("someKey");
try {
myObject=(SomeObject) f.get(5, TimeUnit.SECONDS);
if(myObject != null){
System.out.println("Value from cached object :" + myObject.someField + " thread :{"+Thread.currentThread().getName()+"}");
}else{
System.out.println("Cache is sweeped ! : thread :{"+Thread.currentThread().getName()+"}");
}
} catch(TimeoutException e) {
   // Since we don't need this, go ahead and cancel the operation.  This
   // is not strictly necessary, but it'll save some work on the server.
   f.cancel(false);
   // Do other timeout related stuff
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.setName(threadName);
return thread;
}

}