###解决了,我之前不知道为什么 @Autowried会失败,最后我使用手动注入RedisUtils,成功了。
将原本的自动注入:
@Autowired
private RedisUtils redisUtil
改为手动注入:
private RedisUtils redisUtil = BeanUtils.getBean(RedisUtils.class);
Bean工具类:
@Component
public class BeanUtils implements ApplicationContextAware {
protected static ApplicationContext applicationContext ;
@Override
public void setApplicationContext(ApplicationContext arg0) throws BeansException {
if (applicationContext == null) {
applicationContext = arg0;
}
}
/**
* 拿到ApplicationContext对象实例后就可以手动获取Bean的注入实例对象
*/
public static <T> T getBean(Class<T> clazz) {
return applicationContext.getBean(clazz);
}
}
完美解决