我已经创建了一个简单的单元测试,但是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-boot 2.0和intellij 2018.1.1终极版,我也遇到了同样的问题。
我通过在主应用程序类中放置@EnableAutoConfiguration来解决这个问题
@SpringBootApplication
@EnableAutoConfiguration
class App{
/**/
}
在最新的IntelliJ中,这似乎仍然是一个bug,与可能的缓存问题有关?
如果您将@Repository注释添加为上面提到的mk321,保存,然后删除注释并再次保存,这将解决问题。
你需要做的就是添加
AppConfiguration.java中的@ComponentScan("package/include/your/annotation/component")
因为我认为你的AppConfiguraion.java的包比你的注释组件(@Service, @Component…)的包更深,
比如“package/include/your/annotation/component/deep /config”。
我的IntelliJ IDEA Ultimate版本(2016.3.4 Build 163)似乎支持这一点。诀窍在于您需要启用Spring Data插件。
有时——就我而言——原因是一个错误的输入。我不小心导入了
import org.jvnet.hk2.annotations.Service
而不是
import org.springframework.stereotype.Service
盲目地接受Idea建议的导入中的第一个选择。第一次发生的时候我花了几分钟:-)