【问题标题】:Application Context in SpringBoot Integration testsSpring Boot 集成测试中的应用程序上下文
【发布时间】:2021-10-02 08:38:14
【问题描述】:

我有一个 Spring Boot 集成测试:

@SpringBootTest
@ActiveProfiles("test")
public class ProductServiceIT {
}

当我运行它时,我得到以下异常:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error 
creating bean with name 'adminPostsController' defined in file 

此 AdminPostsController 与此集成测试无关。并且仅因为它位于应用程序上下文中而被调用。 当然我可以在我的测试中将它添加为@MockBean,但这似乎不是最好的解决方案。 有人可以帮助我如何仅为此服务启动应用程序上下文,类似于@WebMvcTest(ProductsController.class),或者给我一些其他解决方案的提示。

【问题讨论】:

  • 如果您有任何问题或需要更多信息,请直接询问,不要只是投反对票。这没有帮助

标签: java spring spring-boot


【解决方案1】:

问题是由存储库中的无效方法引起的,它看起来像是测试上下文中的错误。抱歉,应用程序上下文可能非常混乱。

【讨论】:

    猜你喜欢
    • 2018-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 2018-01-20
    • 1970-01-01
    • 2023-01-25
    • 2020-04-25
    相关资源
    最近更新 更多