我有一個非常簡單的Spring Boot項目,它剛剛從升級到Spring Boot 1.3.0.M5
(然後依賴於Spring 4.2.0.RELEASE
),現在我的項目不能編譯。ContextConfiguration註釋異常
項目:
@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableEncryptableProperties
public class MyApp extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
測試失敗編譯(我只測試ATM):
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {MyApp.class})
@DirtiesContext
public class MyDAO_DataTest {
@Autowired
MyDAO dao;
@Test
public void whenDoingAtest() throws Exception {
//...
}
}
當我嘗試編譯,失敗對我的測試文件,他說:
org.springframework.core.annotation.AnnotationConfigurationException:用於註釋的AnnotationAttributes [org.springframework.test.context.ContextC在[class com.example.MyDAO_DataTest]上聲明的[onfiguration],屬性[locations]及其別名[value]被聲明爲[{}]和[{class com.example.MyApp}]的值,但只允許一個聲明。
我發現feature that's the origin of the exception,但我真的不明白我能做些什麼。
更新我修改這一行的 「固定」 的問題:
@SpringApplicationConfiguration(classes = {MyApp.class})
...這樣的:
@ContextConfiguration(classes = {MyApp.class},
loader = SpringApplicationContextLoader.class)
有效地解決這個問題的工作,並讓自己的工作,但我不明白爲什麼我必須這樣做。 @SpringApplicationConfiguration
被描述爲Similar to the standard ContextConfiguration but uses Spring Boot's SpringApplicationContextLoader,那麼這是怎麼回事?
只是一個友好的注意,如果你找到答案,你的問題可以接受的一個,隨意[接受](http://stackoverflow.com/help/accepted如果你想。 –