0

我正在使用 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
4

1 回答 1

0

JAXBContext 没有构造函数;您使用工厂方法。但是如果该<constructor-arg>元素也可以用于工厂方法ǹewInstance`,请注意参数绝不是ArrayList。如果要在一个上下文中组合两个包,请使用 String 值

"com.xxx.aaa:com.xxx.bbb"

作为构造函数/工厂方法的简单字符串参数。

于 2014-08-20T14:50:35.843 回答