BeanCreationException:在类路径资源[context.xml]中定义的名称为“castorMarshaller”的bean创建时出错:

时间:2015-04-07 11:37:22

标签: xml spring spring-mvc

我尝试使用Spring进行编组。但是我无法通过application.xml在“spring-oxm”中实例化 “castorMarshaller” [context.xml中]。

在搜索原因时我发现“spring-oxm”中有失效。但我使用的是最新版本。但是我收到以下错误。

任何人都可以告诉解决方案修复它。如果有这个问题的补丁,请告诉我在哪里可以得到.......

context.xml中: -

    <bean id="XMLConverter" class="com.servion.springmarshalling.XMLConverter">
    <property name="marshaller" ref="castorMarshaller" />
    <property name="unmarshaller" ref="castorMarshaller" />
</bean>
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller" />

我得到的例外: -

**Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'castorMarshaller' defined in class path resource [context.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/exolab/castor/xml/XMLException
at** org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 15 more

1 个答案:

答案 0 :(得分:2)

您需要在pom.xml中添加以下依赖项:

<!-- Uses Castor for XML -->
<dependency>
    <groupId>org.codehaus.castor</groupId>
    <artifactId>castor</artifactId>
    <version>1.3.3</version>
</dependency>

<!-- Castor need this -->
<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.11.0</version>
</dependency>