RedisTemplateはタイプ別に注入できません

2251 ワード

今日RedisTemplateのテストをして、Spring bootの中で自動的にRedisTemplateを注入して、テストは間違っています.
@Autowired
private RedisTemplate redisTemplate; 

エラー:
Caused by: 
org.springframework.beans.factory.NoSuchBeanDefinitionException: 

No qualifying bean of type 'org.springframework.data.redis.core.RedisTemplate' available: 

expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: 

{@org.springframework.beans.factory.annotation.Autowired(required=true)}

スプリングbootドキュメントを見ると、次のような言葉があります.
If you add a @Bean of your own of any of the auto-configured types it will replace the default
 (except in the case of RedisTemplate the exclusion is based on the bean nameredisTemplatenot its type). 

Spring bootドキュメント
コードを次のように変更します.
@Resource 
private RedisTemplate redisTemplate; 

テストに合格した.
テキスト