Java ContextConfiguration注释异常
我有一个非常简单的Spring Boot项目,它刚刚从Java ContextConfiguration注释异常,java,spring,Java,Spring,我有一个非常简单的Spring Boot项目,它刚刚从Spring Boot 1.2.5.RELEASE升级到Spring Boot 1.3.0.M5(它依赖于Spring 4.2.0.RELEASE),现在我的项目不会编译 项目: @Configuration @ComponentScan @EnableAutoConfiguration @EnableEncryptableProperties public class MyApp extends WebMvcConfigurerAdapte
Spring Boot 1.2.5.RELEASE
升级到Spring Boot 1.3.0.M5
(它依赖于Spring 4.2.0.RELEASE
),现在我的项目不会编译
项目:
@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableEncryptableProperties
public class MyApp extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
编译失败的测试(我唯一的测试):
当我尝试编译时,它在我的测试文件上失败,它说:
org.springframework.core.annotation.AnnotationConfigurationException:在[class com.example.MyDAO_DataTest]上声明的注释[org.springframework.test.context.ContextConfiguration]的AnnotationAttributes中,属性[locations]及其别名[value]用[{}]和[{class com.example.MyApp}]的值声明,但只允许一次声明
我找到了答案,但我真的不明白我能做些什么
更新我通过更改此行“修复”了问题:
@SpringApplicationConfiguration(classes = {MyApp.class})
。。。为此:
@ContextConfiguration(classes = {MyApp.class},
loader = SpringApplicationContextLoader.class)
有效地解决这个问题,允许自己工作,但我不明白为什么我必须这样做@SpringApplicationConfiguration
被描述为,那么交易是什么呢
弹簧靴1.3.0.M5(然后依赖于弹簧4.2.0.释放)
不幸的是,这是错误的:Spring Boot 1.3.0.M5明确依赖于Spring Framework 4.2.1,而不是4.2.0
您看到的异常在SpringFramework 4.2.1中得到了解决,特别是在以下问题中
@SpringApplicationConfiguration
所做的更改需要Spring Framework 4.2.1。有关详细信息,请参阅以下问题
@SpringApplicationConfiguration
所做的更改需要Spring Framework 4.2.1。有关详细信息,请参阅以下问题
Sam只是一个友好的提示,如果你认为你的问题的一个答案可以接受,那么你可以随意回答。只是一个友好的提示,如果你认为你的问题的一个答案可以接受,那么你可以随意回答。
@ContextConfiguration(classes = {MyApp.class},
loader = SpringApplicationContextLoader.class)