Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2222

Cannot invoke because "this.redisService" is null

$
0
0

I try to use Redis to set stock value.

@SpringBootTestpublic class RedisDemoTest{    @Resource    private RedisService redisService;    @Test    public void stockTest() {        String value  = redisService.setValue("stock:19",10L).getValue("stock:19");        System.out.println(value);    }}

And here is my RedisService code

I tried both @Resource and @Autowired

@Servicepublic class RedisService {    @Resource    private JedisPool jedisPool;    public RedisService setValue(String key, Long value){        Jedis client = jedisPool.getResource();        client.set(key,value.toString());        client.close();        return this;    }    public String getValue(String key) {        Jedis client = jedisPool.getResource();        String value = client.get(key);        client.close();        return value;    }

it shows 1 usage with setValue method, However I had an java.lang.NullPointerException:Cannot invoke "service.RedisService.setValue(String, java.lang.Long)" because "this.redisService" is null

I hope to print out value 10 which is the set value.


Viewing all articles
Browse latest Browse all 2222

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>