Javax.xml.bind.JAXBException : doesn’t contain ObjectFactory. Class o jaxb.index
I
have a Java Spring web application that I need to use as a SOAP client.
I’m using Maven and I have a main module (WAR) with custom code and a submodule (JAR dependency) with WSDL (I have two WSDL) build classes.
As you can see in the header, an error occurs when I run the application
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>
WSDL classes are generated correctly in the submodules, and two ObjectFactory.class are present in each package
my.package.path.wsdl
my.package.path.wsdlserver
Error thrown during 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
found a couple of threads on this issue, but I couldn’t understand my problem due to the presence of ObjectFactory .class (automatically created by maven-jaxb2-plugin).
Thank you in advance for your support, sorry for my English.
Solution
Ok, I solved the problem of changing the Marshaller Bean definition 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 need to switch from the contextPaths property to packagesToScan