I've a Java Spring Web application that I need to use as SOAP client.
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
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>
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
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
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.
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>
I needed to swtich from contextPaths property to packagesToScan
来源:https://stackoverflow.com/questions/51982549/javax-xml-bind-jaxbexception-doesnt-contain-objectfactory-class-o-jaxb-index