需要找不到类型为“ com.ganesh.utils.JwtUtils2”的bean

时间:2020-06-20 06:22:00

标签: java spring spring-boot dependency-injection autowired

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

我在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.

我不确定我错过了什么。

0 个答案:

没有答案
相关问题