我目前在 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)