事件回顾
起因
事情是这样的,最近在代码中需要使用 Feign 调用第三方服务。所以就是标准的一套操作:
-
- 引入第三方服务 Jar 包。
-
@EnableFeignClients
注解注入 Bean。
-
@Autowired
引入 Bean。
然后也没有在意到 Idea 已经有警告了,直接启动服务了。然后就出现如下错误:
Description:
Field api in com.xxx.service.impl.ServiceImpl required a bean of type 'com.xxx.api.Api' 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.xxx.api.Api' in your configuration.
PS: Idea 的告警为 Could not autowire. No beans of 'Api' type found.
经过
然后结合 Idea 的警告与日志直接就配置 Autowired 的参数 @Autowired(required = false)
算是暂时解决了项目能启动以及 Idea 的警告。
但是。。。