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

文章目录

      • 报错全称
      • 代码
      • 疑似产生的原因
      • 弯路、坑
      • 分析
      • 解决方案

报错全称

也就是在这个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注解。重启

文章目录

      • 报错全称
      • 代码
      • 疑似产生的原因
      • 弯路、坑
      • 分析
      • 解决方案

你可能感兴趣的:(工作遇到的问题,spring,bean)