项目中新增加了一个用Java 调用 .Net Webservice的Bundle,出现了下面的错误日志:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roModelServiceLocatorAdaptor' defined in URL [bundleentry://185.fwk1784707303/META-INF/spring/spring-config.xml]: Initialization of bean failed; nested exception is java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) previously initiated loading for a different type with name "javax/xml/namespace/QName" at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:62) at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:327) at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:87) at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:292)
原因:
引起这个问题的原因只是猜测,在Classpath中有多个javax.xml.namespace.QName,OSGi在loader时用了不同的版本. OSGi的坑太多,具体原因不清楚.
解决方法:
Use construction method of injection for **LocatorAdaptor,将
<bean id="roModelServiceLocatorAdaptor" class="com.moodys.loan.mat.adaptor.ROModelServiceLocatorAdaptor"> <property name="userService" ref="userService" /> </bean>
修改成:
<bean id="roModelServiceLocatorAdaptor" class="com.moodys.loan.mat.adaptor.ROModelServiceLocatorAdaptor"> <constructor-arg ref="userService" /> </bean>