admin管理员组

文章数量:1794759

解决Consider defining a bean of type org.springframework.data.redis.core.RedisTemplate in your configu

解决Consider defining a bean of type org.springframework.data.redis.core.RedisTemplate in your configu

在学习Springboot+redis整合demo时,搭建好项目启动时报如下错误:

*************************** APPLICATION FAILED TO START ***************************

Description:

Field redisTemplate in jypay.spring_cloud_consul_comsumer.controller.TestController required a bean of type 'org.springframework.data.redis.core.RedisTemplate' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.data.redis.core.RedisTemplate' in your configuration.

我查看项目的定义RedisTemplate的类(RedisConfig.java)定义和写法上没错。controller的使用TestController.java使用了RedisTemplate,并且使用@Autowired注入也没错。怎么会出现这种错误呢?于是在网上搜索看别人blog说是启动类ConsuleConsumerApplication.java没有扫描到RedisConfig.java的注解。我添加了@ComponentScan就解决了。如下截图:

其实也可以把需扫描的类放到springboot的启动类同一个包也可以。看自己的项目需求来定了。

本文标签: orgspringframeworktypedefiningbean