首页 > 解决方案 > 需要一个找不到的“com.ganesh.utils.JwtUtils2”类型的 bean

问题描述

这个错误有很多问题,其中大多数与存储库和服务类有关,但我找不到与我的情况完全相关的问题。

我里面的包结构src/main/java/com/ganesh/是这样的

├── ApiApplication.java
├── interceptors
│   └── AuthorizationInterceptor.java
└── utils
    └── JwtUtils.java
... 

JwtUtils定义如下

@Component
public class JwtUtils {
     ... 
}

AuthorizationInterceptor定义为

@Component
public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
    private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizationInterceptor.class);

    @Autowired
    private JwtUtils jwtUtils;
    ... 
}

主类定义为

@SpringBootApplication
public class ApiApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiApplication.class, args);
    }

}

当我运行我得到这个错误。

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

Description:

Field jwtUtils in com.ganesh.interceptors.AuthorizationInterceptor required a bean of type 'com.ganesh.utils.JwtUtils' that could not be found.

The injection point has the following annotations:
        - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.ganesh.utils.JwtUtils' in your configuration.

我不确定我错过了什么。

标签: javaspringspring-bootdependency-injectionautowired

解决方案


推荐阅读