我已经创建了一个简单的单元测试,但是IntelliJ错误地将它突出显示为红色。将其标记为错误
没有豆子?
如你所见,它通过了测试?所以它一定是自动连接的?
我已经创建了一个简单的单元测试,但是IntelliJ错误地将它突出显示为红色。将其标记为错误
没有豆子?
如你所见,它通过了测试?所以它一定是自动连接的?
当前回答
I had similar issue in Spring Boot application. The application utilizes Feign (HTTP client synthetizing requests from annotated interfaces). Having interface SomeClient annotated with @FeignClient, Feign generates runtime proxy class implementing this interface. When some Spring component tries to autowire bean of type SomeClient, Idea complains no bean of type SomeClient found since no real class actually exists in project and Idea is not taught to understand @FeignClient annotation in any way.
解决方案:用@Component注解接口SomeClient。(在我们的例子中,我们没有直接在SomeClient上使用@FeignClient注释,而是使用metaannotation @OurProjectFeignClient,它是带注释的@FeignClient,并向其添加@Component注释也可以工作。)
其他回答
我只能使用@EnableAutoConfiguration来解决它,但是这个错误没有功能上的影响。
我在申请的时候也遇到过类似的问题。 当我添加注释时,不正确的高亮显示消失了。
@ContextConfiguration(classes = {...})
在使用@SpringBootApplication注释创建SpringBoot应用程序时,我也遇到了同样的问题。该注释根据spring引用表示@Configuration、@EnableAutoConfiguration和@ComponentScan。
正如预期的那样,新的注释工作正常,我的应用程序运行顺利,但Intellij一直抱怨未实现的@Autowire依赖项。当我重新分别使用@Configuration、@EnableAutoConfiguration和@ComponentScan时,错误就停止了。Intellij 14.0.3(很可能是更早的版本)似乎还没有配置为识别@SpringBootApplication注释。
现在,如果错误对您的影响如此之大,那么就恢复到那三个单独的注释。否则,忽略Intellij…您的依赖项解析配置正确,因为您的测试通过了。
永远记得……
人永远比机器伟大。
我使用的是spring-boot 2.0和intellij 2018.1.1终极版,我也遇到了同样的问题。
我通过在主应用程序类中放置@EnableAutoConfiguration来解决这个问题
@SpringBootApplication
@EnableAutoConfiguration
class App{
/**/
}
至于intelliJ 2021.2.3版(终极版),我把“spring bean组件中不正确的注入点自动装配”改为警告,这对我来说很有用