Parameter 1 of constructor in com.xxx.controller.Xxx required a bean of type

欧旻
2023-12-01

报错全称

也就是在这个Java类里面的注入的接口需要一个Bean实现,

Parameter 1 of constructor in com.abc.auth.controller.TokenController required a bean of type 'org.springframework.cache.CacheManager' that could not be found.

The following candidates were found but could not be injected:
	- Bean method 'cacheManager' in 'CaffeineCacheConfiguration' not loaded because @ConditionalOnClass did not find required class 'com.github.benmanes.caffeine.cache.Caffeine'
	- Bean method 'cacheManager' in 'EhCacheCacheConfiguration' not loaded because @ConditionalOnClass did not find required class 'net.sf.ehcache.Cache'
	- Bean method 'cacheManager' in 'JCacheCacheConfiguration' not loaded because @ConditionalOnClass did not find required class 'javax.cache.Caching'


Action:

Consider revisiting the entries above or defining a bean of type 'org.springframework.cache.CacheManager' in your configuration.

代码

@RequiredArgsConstructor
public class TokenController {
    @Autowired
    private TokenStore tokenStore;
    //    private RedisTemplate redisTemplate;
//    private CacheManager cacheManager;
    @Autowired
    private final RedisTemplate redisTemplate;
    private final CacheManager cacheManager;

疑似产生的原因

没有找到cacheManager的实现

弯路、坑

分析

cacheManager被final修饰符修饰
@RequiredArgsConstructor的意思是:

Lombok注解释义
@RequiredArgsConstructor生成包含常量、标识了NotNull的变量的构造方法。生成的构造方法是私有的private
@NoArgsConstructor生成无参的构造方法
@AllArgsContructor生成包含所有属性的构造器

解决方案

1) 去掉final、去掉@RequiredArgsConstructor注解。重启

 类似资料:

相关阅读

相关文章

相关问答