我正在使用spring mvc。我在App-config.xml中配置了两个jaxb上下文,如下所示。 因此我在Tomcat服务器上运行我的项目时遇到了问题。所以我们迁移到Liberty Was(8.0)服务器。然后它开始正常工作。
<bean id="jaxbContext" class="javax.xml.bind.JAXBContext" factory-method="newInstance">
<constructor-arg>
<list>
<value>com.xxx.aaa</value>
</list>
</constructor-arg>
</bean>
<bean id="jaxbContextnew" class="javax.xml.bind.JAXBContext" factory-method="newInstance">
<constructor-arg>
<list>
<value>com.xxx.bbb</value>
</list>
</constructor-arg>
</bean>
现在,在使用spring junit 4 runner运行JUnit测试用例时,我遇到了以下错误。 实际配置很好。 1)请说明配置两个jaxb上下文需要做什么。 要么 2)我们可以在单独运行juint时指向自定义jaxb实现吗? 如何确定我的Web应用程序正在使用哪个jaxb上下文?
TRACE DefaultListableBeanFactory - Ignoring factory method [public static javax.xml.bind.JAXBContext javax.xml.bind.JAXBContext.newInstance(java.lang.String,java.lang.ClassLoader,java.util.Map) throws javax.xml.bind.JAXBException] of bean 'jaxbContextnew': org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jaxbContextNew' defined in URL [file:src/main/webapp/WEB-INF/spring/app-config.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: Could not convert factory method argument value of type [java.util.ArrayList] to required type [java.lang.String]: Failed to convert value of type 'java.util.ArrayList' to required type 'java.lang.String'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [java.lang.String]: no matching editors or conversion strategy found
TRACE DefaultListableBeanFactory - Ignoring factory method [public static javax.xml.bind.JAXBContext javax.xml.bind.JAXBContext.newInstance(java.lang.String,java.lang.ClassLoader) throws javax.xml.bind.JAXBException] of bean 'jaxbContextNew': org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jaxbContextNew' defined in URL [file:src/main/webapp/WEB-INF/spring/app-config.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: Could not convert factory method argument value of type [java.util.ArrayList] to required type [java.lang.String]: Failed to convert value of type 'java.util.ArrayList' to required type 'java.lang.String'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [java.lang.String]: no matching editors or conversion strategy found
TRACE DefaultListableBeanFactory - Ignoring factory method [public static javax.xml.bind.JAXBContext javax.xml.bind.JAXBContext.newInstance(java.lang.Class[],java.util.Map) throws javax.xml.bind.JAXBException] of bean 'jaxbContextNew': org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jaxbContextNew' defined in URL [file:src/main/webapp/WEB-INF/spring/app-config.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [java.util.Map]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?
TRACE DefaultListableBeanFactory - Ignoring factory method [public static javax.xml.bind.JAXBContext javax.xml.bind.JAXBContext.newInstance(java.lang.String) throws javax.xml.bind.JAXBException] of bean 'jaxbContextNew': org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jaxbContextNew' defined in URL [file:src/main/webapp/WEB-INF/spring/app-config.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: Could not convert factory method argument value of type [java.util.ArrayList] to required type [java.lang.String]: Failed to convert value of type 'java.util.ArrayList' to required type 'java.lang.String'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [java.lang.String]: no matching editors or conversion strategy found
答案 0 :(得分:0)
没有JAXBContext的构造函数;你使用工厂方法。但是如果<constructor-arg>
元素可以用于工厂方法ǹewInstance`,请注意该参数永远不是ArrayList。如果要在单个上下文中组合两个包,请使用String值
"com.xxx.aaa:com.xxx.bbb"
作为构造函数/工厂方法的简单String参数。