我已经创建了一个简单的单元测试,但是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注释也可以工作。)
其他回答
我也遇到过这个问题,并通过删除Spring Facet来解决它:
File ->项目结构 选择方面 拆卸弹簧
好运!
我的IntelliJ IDEA Ultimate版本(2016.3.4 Build 163)似乎支持这一点。诀窍在于您需要启用Spring Data插件。
在最新的IntelliJ中,这似乎仍然是一个bug,与可能的缓存问题有关?
如果您将@Repository注释添加为上面提到的mk321,保存,然后删除注释并再次保存,这将解决问题。
有时需要指明@ComponentScan应该在哪里扫描组件。你可以通过将包作为这个注释的参数来实现,例如:
@ComponentScan(basePackages={"path.to.my.components","path.to.my.othercomponents"})
然而,正如前面提到的,@SpringBootApplication注释替换了@ComponentScan,因此在这种情况下,你必须做同样的事情:
@SpringBootApplication(scanBasePackages={"path.to.my.components","path.to.my.othercomponents"})
至少在我的案例中,Intellij停止了抱怨。
对我来说,解决方案是把@EnableAutoConfiguration放在Application类的@SpringBootApplication下面,因为它是多余的,所以它要下划线。删除它,瞧,所有关于丢失豆子的警告都消失了!傻春……