Spring版本冲突问题

一下错误是因为在MyEclipse中导入xfire会自动导入spring1.2.6,然后自己又导入spring2.0引起的版本冲突(仅在使用ClassPathXmlApplicationContext,FileSystemXmlApplicationContext的情况下),导致程序无法做单元测试。

java.lang.IllegalStateException: Could not find valid implementation for: 2.0
    at org.apache.xbean.spring.context.impl.XBeanHelper.createBeanDefinitionReader(XBeanHelper.java:48)
    at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.loadBeanDefinitions(ClassPathXmlApplicationContext.java:170)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:269)
    at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:161)
    at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:51)
    at com.wasu.lwms.test.TestMySpaceUserCatalogSqlMap.testSearchSuggest(TestMySpaceUserCatalogSqlMap.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.apache.xbean.spring.context.impl.XBeanHelper.createBeanDefinitionReader(XBeanHelper.java:46)
    ... 24 more
Caused by: java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlBeanDefinitionReader.setValidationMode(I)V
    at org.apache.xbean.spring.context.v2.XBeanXmlBeanDefinitionReader.<init>(XBeanXmlBeanDefinitionReader.java:58)
    ... 29 more

在不修改配置的情况下的解决方法:换成使用XmlWebApplicationContext即可,代码如下:

ConfigurableWebApplicationContext ctx = new XmlWebApplicationContext();
		ctx.setConfigLocations(new String[] { "classpath:applicationContext.xml" });
		ctx.refresh();

你可能感兴趣的:(java,apache,eclipse,spring,JUnit)