我已经创建了一个简单的单元测试,但是IntelliJ错误地将它突出显示为红色。将其标记为错误

没有豆子?

如你所见,它通过了测试?所以它一定是自动连接的?


当前回答

@Autowired(required = false) 能让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注释也可以工作。)

我删除了这段代码。不再有错误


另一种检查方法: 将@Service注释添加到Repository类中,它应该可以工作。

你需要做的就是添加

AppConfiguration.java中的@ComponentScan("package/include/your/annotation/component")

因为我认为你的AppConfiguraion.java的包比你的注释组件(@Service, @Component…)的包更深,

比如“package/include/your/annotation/component/deep /config”。

你所需要做的是让这个工作是以下代码:

@ComponentScan
public class PriceWatchTest{

    @Autowired
    private PriceWatchJpaRepository priceWatchJpaRepository;
...
...
}

作为IntelliJ (IDE)和开发环境之间的大多数同步错误。

特别是如果您有自动测试或构建,通过绿色始终。

无效缓存和重新启动解决了我的问题。