java - Why is redis throwing NullPointerException running via JUnit with spring and default config? -


i'm working on os x java 7, spring 3.2, jedis 2.1.0, spring-data-redis 1.1.1, trying bare-bones redis set working default redis configuration. meaning haven't put redis.conf file. when

redis-server 

it says started , ready accept connections on port 6379.

initially, tried annotated beans redistemplate , jedisconnectionfactory, spring complained couldn't create or find beans, did way. maybe indicating more basic problem. did longer version below, @ least appears create redis , jedis components.

here test :

@runwith(springjunit4classrunner.class) @contextconfiguration(loader=annotationconfigcontextloader.class) public class redistest {     @configuration     static class contextconfiguration {       }      redistemplate<string, string> template;      private jedisconnectionfactory getjedisconnectionfactory() {         jedisconnectionfactory factory = new jedisconnectionfactory();         factory.sethostname("localhost");         factory.setport(6379);         factory.setusepool(true);         return factory;     }      private redistemplate<string, string> getredistemplate() {         redistemplate<string, string> redistemplate = new redistemplate<string, string>();         redistemplate.setconnectionfactory(getjedisconnectionfactory());         return redistemplate;     }      @test     public void testredis() {         system.out.println("testing redis ");          template = getredistemplate();          template.opsforvalue().set("key", "value");         string value = template.opsforvalue().get("key");         system.out.println("got value : " + value);     } } 

and top of error stack trace

java.lang.nullpointerexception java.lang.nullpointerexception     @ org.springframework.data.redis.core.abstractoperations.rawvalue(abstractoperations.java:110)     @ org.springframework.data.redis.core.defaultvalueoperations.set(defaultvalueoperations.java:166)     @ com.mycompany.storage.redistest.testredis(redistest.java:46) 

the problem both redistemplate , jedisconnectionfactory need have afterpropertiesset() called. called spring configuration, since wasn't working me, has called explicitly.

also, theses lines

 factory.sethostname("localhost")  factory.setport(6379)  factory.setusepool(true) 

are unnecessary because default values.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -