我在java/
目錄(同一個包)中有一個@SpringBootApplication類,test/
中有另一個@SpringBootApplication類用於模擬一些自動連接的bean。有幾種測試,使用哪種配置因測試而異。在Spring Boot 1.4中的@WebMvcTest時排除配置
而且在測試類
@RunWith(SpringRunner.class)
@WebMvcTest(RecApiServerController.class)
拋出
java.lang.IllegalStateException: Found multiple @SpringBootConfiguration annotated classes [Generic bean: class [com.xxx.MockedTestConfig]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [/..direction.../target/test-classes/com/xxx/MockedTestConfig.class], Generic bean: class [com.xxx.MyApplication]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [/...direction.../target/classes/com/xxx/MyApplication.class]]
我只是想測試控制器的路由。
我該如何設置特定的應用程序配置?
我在@SpringBootTest中將'MockedTestConfig.class'更改爲常規@Configuration並添加'classes = {MyApplication.class,MockedTestConfig.class}',並且所有測試都正常工作。他們之前沒有,所以我將它改爲@SpringBootApplication。我認爲那個時候'class'中的順序是錯誤的。謝謝。 :) – margincall