我有一个 Java Spring Web 应用程序,需要将其用作 SOAP 客户端。
我正在使用 Maven,并且有一个包含自定义代码的主模块 (WAR) 和一个包含 WSDL(我有两个 WSDL)生成的类的子模块(JAR 依赖项)。
正如您在标题中看到的,当我运行应用程序时发生错误
javax.xml.bind.JAXBException: doesn't contain ObjectFactory.class or jaxb.index
这是主模块的ApplicationContext.xml:
<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:
my.package.path.wsdl
my.package.path.wsdlserver
在 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 自动创建),因此我无法理解我的情况下的问题。
预先感谢您的支持,并对我的英语表示抱歉。