文章目录
Springboot 通过ApplicationContext 读取StringRedisTemplate 的bean,No bean named ‘stringRedisTemplate’
1、通过ApplicationContextAware 注册applicationContext并获取容器中的bean
public static Object get(String name) {
return applicationContext.getBean(name);
}
2、Springboot 自己实现的 StringRedisTemplate
我们在注入Springboot 自己实现的 StringRedisTemplate 进行Redis 操作时,必须按照如下方式进行命名,否则报错找不到Bean
@Autowired
protected StringRedisTemplate stringRedisTemplate;