我必須爲Mule ESB + Spring項目進行單元測試,直到找到以下阻塞爲止: 我java.lang.NoSuchMethodError:org.springframework.core.type.classreading.CachingMetadataReaderFactory.clearCache()V 當我執行測試:如何在Junit for spring + mule ESB項目中爲clearCache()方法解決java.lang.NoSuchMethodError
我只調用單元測試如下:
//annotations
@TransactionConfiguration(defaultRollback = true)
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/platform-context-test.xml" })
public class AbstractExceptionUnitTest {
private static final Logger LOG = Logger.getLogger(AbstractExceptionUnitTest.class);
@BeforeClass
public static void setUpClass() throws Exception {
LOG.info("Testing " + AbstractExceptionUnitTest.class);
JndiSetup.doSetup();
}
/**
* Method testApp.
*/
@Test
public void test() {
LOG.info("Testing!!");
}
}
我看到輸出春天背景:
信息17-10 20:09:33,155 - @TestExecutionListeners不存在的類[類com.tesing.AbstractExceptionUnitTest]:使用默認值。 INFO 17-10 20:09:33,181 - 測試類com.tesing.AbstractExceptionUnitTest INFO 17-10 20:09:33,248 - 數據源MySQL - > myDataSourceDS綁定。 INFO 17-10 20:09:33,356 - 從類路徑資源[platform-context-test.xml]加載XML bean定義 INFO 17-10 20:09:33,689 - 刷新org.springframework.context.support.GenericApplicationContext @ 7af485b:啓動日期[Thu Oct 17 20:09:33 COT 2013];上下文結構的根
,之後的測試顯示錯誤:
java.lang.NoSuchMethodError: org.springframework.core.type.classreading.CachingMetadataReaderFactory.clearCache()V
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:325)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
在這裏,該項目的相關依賴部分:
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-core</artifactId>
<version>4.4.0-stable</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-db</artifactId>
<version>4.4.0-stable</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-engine</artifactId>
<version>4.4.0-stable</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>directory-naming</groupId>
<artifactId>naming-java</artifactId>
<version>0.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>central-mule.repository</id>
<name>Mule Plugins</name>
<url>https://repository.mulesoft.org/releases/</url>
</repository>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<id>PentahoRepo</id>
<name>Pentaho repository</name>
<url>http://repository.pentaho.org/artifactory/repo</url>
</repository>
<repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>mulesoft-release</id>
<name>mulesoft release repository</name>
<url>https://repository.mulesoft.org/releases/</url>
</pluginRepository>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
請任何想法去嘗試解決這個NoShuchMethodError?
我解決了一些類似的NoSuchMethod升級彈簧依賴關係的版本或排除在依賴關係中引用舊的彈簧依賴關係,但在這個項目中,我沒有發現spring-core依賴關係早於3.1.1版本。 – jastonitas