2015-12-09 90 views
3

運行測試,堆棧跟蹤是完全Spring框架和JUnit:升級至彈簧引導1.3導致java.lang.NoSuchMethodError:org.springframework.beans.factory.config.ConfigurableBeanFactory.getSingletonMutex()

java.lang.NoSuchMethodError: org.springframework.beans.factory.config.ConfigurableBeanFactory.getSingletonMutex()Ljava/lang/Object; 
    at org.springframework.context.event.AbstractApplicationEventMulticaster.setBeanFactory(AbstractApplicationEventMulticaster.java:86) 
    at org.springframework.boot.context.event.EventPublishingRunListener.registerApplicationEventMulticaster(EventPublishingRunListener.java:81) 
    at org.springframework.boot.context.event.EventPublishingRunListener.contextPrepared(EventPublishingRunListener.java:71) 
    at org.springframework.boot.SpringApplicationRunListeners.contextPrepared(SpringApplicationRunListeners.java:60) 
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:329) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:295) 
    at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.java:98) 
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) 
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) 
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) 
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) 
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) 
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) 
    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.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:193) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) 

測試類很簡單:

package com.uss.identity.dao; 

import com.uss.identity.TestApplication; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.boot.test.SpringApplicationConfiguration; 
import org.springframework.test.context.ActiveProfiles; 
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 
import org.springframework.transaction.annotation.EnableTransactionManagement; 

import static org.junit.Assert.assertNull; 

@SuppressWarnings("SpringJavaAutowiredMembersInspection") 
@RunWith(SpringJUnit4ClassRunner.class) 
@SpringApplicationConfiguration(classes = {TestApplication.class}) 
@EnableTransactionManagement 
@ActiveProfiles("test-flyway") 
public class ClientRepoTest2 { 

    @Autowired 
    ClientRepository dao; 

    @Test 
    public void testFindNone() throws Exception { 
     assertNull(dao.findOne("nonesuch")); 
    } 

} 

和引用TestApplication類只是:

package com.uss.identity; 

import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.context.annotation.Profile; 

@SpringBootApplication 
@Profile({"test", "test-flyway"}) 
public class TestApplication { 

} 

當使用Spring Boot 1.2.8.RELEASE時,它工作正常。但試圖升級到1.3.0.RELEASE會導致上述例外。

+0

這是測試org.springframework.data.jpa.repository.JpaRepository的子類。令人費解的是,在聲明該方法的接口上引發異常 - 至少在推定的spring-core版本中:4.2.3.RELEASE。我期望我會看到例外中列出的具體實現類... – sofend

+0

衝突版本的彈簧罐。做一個'mvn dependency:tree'並檢查你的依賴關係,確保它們都是相同的版本。 –

回答

6

您應該使用Spring Boot的依賴管理來確保您爲所有Spring Framework模塊獲得一致且正確的版本。你可以做,要麼通過spring-boot-starter-parent作爲POM的父:

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.3.0.RELEASE</version> 
</parent> 

或者在你的POM的<dependency-management>部分導入它:

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-dependencies</artifactId> 
      <version>1.3.0.RELEASE</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

更多信息,在春季啓動文件的dependency management section可用。

+0

謝謝。這工作。 – sofend

0

在我的情況下,罪魁禍首是activemq-all.jar捆綁舊的春季班。 發現與-verbose:class標誌。

[加載從文件org.springframework.beans.factory.access.BeanFactoryLocator:/ C:/XXX/activemq-all-5.11.3.jar] [加載org.springframework.beans.factory.access.SingletonBeanFactoryLocator從文件:/ C:/XXX/activemq-all-5.11.3.jar] [從文件加載的org.springframework.context.access.ContextSingletonBeanFactoryLocator:/ C:/XXX/activemq-all-5.11.3.jar]