问题
使用Spring OXM + Castor绑定 ,添加了Castor库,但是仍然遇到以下错误消息?
Exception in thread "main" java.lang.RuntimeException:
Could not instantiate serializer org.apache.xml.serialize.XMLSerializer:
java.lang.ClassNotFoundException: org.apache.xml.serialize.XMLSerializer
at org.exolab.castor.xml.XercesSerializer.<init>(XercesSerializer.java:50)
//...
Maven中的Castor依赖关系。
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor</artifactId>
<version>1.2</version>
</dependency>
解
如果没有记错, Castor需要Xerces来工作 ,因此,您还需要添加Xerces依赖项。
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
翻译自: https://mkyong.com/spring3/classnotfoundexception-org-apache-xml-serialize-xmlserializer/