1.在类上直接加注解@Component,那么这个类就直接注入到Spring容器中了 ,像@Contrloller,@Service这些本质上都是@Component, 2.@Configuration(或者@SpringBootConfiguration)放到类上,然后在类中的方法上加注解@Bean @SpringBootConfigurationpublic class UseConditionalOnBean { @Bean public User createBean(){ retur
最近,在项目开发过程中使用了RedisTemplate,进行单元测试时提示“Field redisTemplate in com.example.demo1.dao.RedisDao required a bean of type ‘org.springframework.data.redis.core.RedisTemplate’ that could not be found”,翻译过来就是“找不到类型为RedisTemplate的bean”.当然,仅看这句话我们无法确定为什么会出现这个问题