小编use*_*695的帖子

使用多 Maven 项目设置测试 Spring Boot 应用程序的问题

我目前在 Spring Boot 和多 Maven 项目结构方面遇到了一些问题。我正在使用 Spring Boot 4.3.1。

我的项目结构如下:

parent
-- pom.xml
-- application
   -- pom.xml
   -- src
      -- main
         -- java
            -- Application.java (annotated with @SpringBootApplication)
      -- test
         -- java 
            -- MyApplicationTest.java (annotated with @SpringBootTest)
-- library
   -- pom.xml
   -- src
      -- main
         -- java (...)
      -- test
         -- java
            -- MyLibraryTest.java (annotated with @SpringBootTest)
Run Code Online (Sandbox Code Playgroud)

application模块依赖于library.

MyApplicationTest工作正常,但运行时MyLibraryTest,我失败并出现以下错误:

    java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your …
Run Code Online (Sandbox Code Playgroud)

java dependencies maven spring-boot spring-boot-test

5
推荐指数
1
解决办法
2208
查看次数