protected static RedisTemplate<Serializable, Serializable> redisTemplate;
注入redis
spring的配置文件 配置了 @RESOURCE注解不起作用
然后适了 @autowired也用了 但是 不知道为什么 扫描的时候 redisTemplate都是null值
@Component public class RedisUtils { @Resource protected RedisTemplate<Serializable, Serializable> redisTemplate; protected static RedisUtils ru; @PostConstruct public void init(){ ru = this; ru.redisTemplate = this.redisTemplate; } public static boolean addFile(final String key, final Object obj) { boolean result = ru.redisTemplate.execute(new RedisCallback<Boolean>() { public Boolean doInRedis(RedisConnection connection) throws DataBindingException { RedisSerializer<String> serializer = ru.redisTemplate.getStringSerializer(); byte[] key1 = serializer.serialize(key); // byte[] name = serializer.serialize(); return connection.setNX(key1,(byte[])obj); } }); return result; } 老是null 取不到值。。。。。。。。。。。。
是不是因为静态的static
http://blog.csdn.net/wang_huanming/article/details/46545825