我正在使用spring的Jaxb2Marshaller(没有Web服务)来解组一些xml。 xml代码是通过maven-jaxb-plugin编写的代码,我通过以下方式实例化Jaxb2Marshaller:
<bean id="unmarshaller" class="...Jaxb2Marshaller" p:contextPath="my.package.path" />
然后从:
开始mvn clean package
mvn tomcat:run
第一个unmarshaller被创建得很好,第二个用org.springframework.oxm.jaxb.JaxbSystemException抛出,因为它找不到ObjectFactory(由maven-jaxb-plugin生成,我已经验证了其实存在于罐子里,在正确的包装中)。
我实际上有两个unmarshallers,(虽然我尝试过一个unmarshaller和contextPath与冒号分隔的包路径,结果相同)。
我不认为这通常是spring或我的配置的问题,因为如果我部署到一个完整的tomcat容器,它工作正常。我注意到maven将tomcat放在我的project / target / tomcat文件夹中,并且存在一些差异,例如没有lib目录。我实际上不知道嵌入式tomcat和常规安装之间有什么区别。
有人可以解释一下:
1)嵌入式tomcat与常规安装的确切区别
2)如果有已知的限制
3)如果它可以配置为在这个位置正常工作
完整堆栈跟踪:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'unmarshaller' defined in class path resource [spring.xml]: Invocation of init method failed; nested exception is org.springframework.oxm.jaxb.JaxbSystemException: "my.package.path" doesnt contain ObjectFactory.class or jaxb.index; nested exception is javax.xml.bind.JAXBException: "my.package.path" doesnt contain ObjectFactory.class or jaxb.index
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.startup.Embedded.start(Embedded.java:825)
at org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)
at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)
答案 0 :(得分:2)
对于遇到此问题的其他人,我最终通过使用classesToBeBound属性而不是contextPath来解决问题。我最初避免使用classesToBeBound的原因是我认为我必须在classesToBeBound列表中指定模型中的每个类,但事实并非如此。您只需指定具有@XmlRootElement注释的类。