2015-09-23 48 views
1

我有一個非常簡單的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,那麼這是怎麼回事?

+0

只是一個友好的注意,如果你找到答案,你的問題可以接受的一個,隨意[接受](http://stackoverflow.com/help/accepted如果你想。 –

回答

0

春季啓動1.3.0.M5(然後依靠彈簧4.2.0.RELEASE)

這不幸不正確的:春天啓動1.3.0.M5明確地依賴於Spring框架4.2。 1,而不是4.2.0。

您看到的異常在Spring Framework 4.2.1中解決,特別是在以下問題中。

而且需要 Spring框架4.2.1在春季啓動1.3.0 M5到@SpringApplicationConfiguration所做的更改。有關詳情,請參閱以下問題。

因此,確保你對Spring框架4.2.1運行應該解決您的問題。

問候,

山姆

相關問題