非spring注入使用RedisTemplate,需先调用afterPropertiesSet()方法

错误信息:

Exception in thread "main" java.lang.IllegalArgumentException: template not initialized; call afterPropertiesSet() before using it
    at org.springframework.util.Assert.isTrue(Assert.java:92)
    at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:183)
    at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169)
    at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:91)
    at org.springframework.data.redis.core.DefaultListOperations.rightPush(DefaultListOperations.java:184)
    at com.zbz.redis.client.RedisTemplateClient.main(RedisTemplateClient.java:41)

从错误信息知,需要先调用afterPropertiesSet方法,此方法是应该是初始化参数和初始化工作。

你可能感兴趣的:(springMVC)