问题描述
我有一个Java Spring Web应用程序需要用作SOAP客户端。
I've a Java Spring Web application that I need to use as SOAP client.
我正在使用Maven并且我有一个主模块(WAR用我的自定义代码和一个子模块(JAR依赖)和WSDL(我有两个WSDL)生成的类。
I'm using Maven and I've got a main module (WAR) with my custom code and a child module (JAR dependency) with the WSDLs (I've two WSDL) generated classes.
正如你在标题中看到的那样我运行应用程序发生错误
As you can see in the title when I run the application an error occurs
javax.xml.bind.JAXBException: doesn't contain ObjectFactory.class or jaxb.index
这是主模块的ApplicationContext.xml:
This is the ApplicationContext.xml of the main module:
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory"/>
<property name="marshaller" ref="marshaller" />
<property name="unmarshaller" ref="marshaller" />
<property name="interceptors">
<list>
<ref bean="wsSecurityInterceptor" />
</list>
</property>
</bean>
<bean id="wsSecurityInterceptor" class="org.springframework.ws.soap.security.wss4j2.Wss4jSecurityInterceptor">
<property name="securementActions" value="UsernameToken" />
<property name="securementUsername" value="xxx" />
<property name="securementPassword" value="xxxx" />
<property name="securementPasswordType" value="PasswordText" />
</bean>
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPaths">
<list value-type="java.lang.String">
<value>my.package.path.wsdl</value>
<value>my.package.path.wsdlserver</value>
</list>
</property>
</bean>
在子模块中正确生成WSDL类,每个包中都有两个ObjectFactory.class:
into the child module the WSDL classes are generated correctly and two ObjectFactory.class are presents in each package:
my.package.path.wsdl
my.package.path.wsdlserver
Marshaller Bean期间出现错误:
Error is raised during the Marshaller Bean:
Error creating bean with name 'marshaller' defined in ServletContext resource
...
javax.xml.bind.JAXBException: "my.package.path.wsdl" doesn't contains ObjectFactory.class or jaxb.index
我发现了几个关于这个问题的线索,但我无法理解这个问题在我的情况下,由于ObjectFactory.class是存在的事实(由maven-jaxb2-plugin自动创建。
I've found several threads about this problem but I can't understand the issue in my case due to the fact that the ObjectFactory.class are presents (automatically created by the maven-jaxb2-plugin.
提前感谢您的支持并抱歉我的英语。
Thanks in advance for your support and sorry for my english.
推荐答案
好的,我解决了以这种方式改变Marshaller Bean的定义:
Ok I solved changing the Marshaller Bean definition in this way:
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="packagesToScan">
<list>
<value>my.package.path.wsdl</value>
<value>my.package.path.wsdlserver</value>
</list>
</property>
</bean>
我需要从 contextPaths 属性切换到 packagesToScan
这篇关于javax.xml.bind.JAXBException:不包含ObjectFactory.class o jaxb.index的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!