我正在尝试使用spring和gradle为项目编写一些junit测试。我正在
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.boot.test.autoconfigure.AutoConfigureReportTestExecutionListener.prepareTestInstance(AutoConfigureReportTestExecutionListener.java:49)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationContextInitializer : org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:381)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:358)
at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:230)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:206)
at org.springframework.boot.test.context.SpringBootContextLoader.getSpringApplication(SpringBootContextLoader.java:121)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:84)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 25 more
Caused by: java.lang.NoSuchMethodException: org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.getConstructor(Class.java:1825)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:376)
... 32 more
有人告诉我,这可能是弹簧组件不兼容的问题。这些是我gradle.properties中的那些
SpringSecurityConfig = 4.0.2.RELEASE
SpringSecurityWeb = 4.0.2.RELEASE
SpringWeb = 4.3.6.RELEASE
SpringWebMVC = 4.3.6.RELEASE
SpringBootTestAutoConfigure = 1.4.0.RELEASE
SpringSecurityTest = 4.0.2.RELEASE
SpringContextVersion = 4.1.7.RELEASE
SpringTestVersion = 4.3.6.RELEASE
SpringBootTestVersion = 1.2.5.RELEASE
SpringBootStarterVersion = 1.2.5.RELEASE
SpringDataRedisVersion = 1.6.4.RELEASE
SpringRetryVersion = 1.2.0.RELEASE
SpringDataJpaVersion = 1.8.0.RELEASE
我如何找出其中哪些不兼容?
答案 0 :(得分:0)
运行
gradle dependencies --configuration compile
输出显示版本已更改的地方,例如spring-beans:4.1.6.RELEASE -> 4.1.7.RELEASE
因为spring-security-web
4.0.2想要spring-beans
4.1.6,而spring-boot-starter
1.2.5想要spring-core
4.1.7
冲突的竞争者是:
SpringBootTestAutoConfigure = 1.4.0.RELEASE
depends on spring-boot:1.4.0.RELEASE and spring-core:4.3.2.RELEASE
SpringBootStarterVersion = 1.2.5.RELEASE
depends on spring-boot:1.2.5.RELEASE and spring-core:4.1.7.RELEASE