Using Spring CXF descriptors in WildFly

In some cases, users might still want to consume Spring cxf.xml descriptors. On client side, in order to do that, the Spring libraries need to be available in the current thread classloader. For the Web Services stack to have correct visibility over Spring classes, the Spring libraries need to be properly installed in a specific WildFly module, the org.springframework.spring module, which many Web Services stack modules on the server already have optional dependencies to.

Installing Spring libraries in that module is basically a matter of copying the Spring jars in the correct path (JBOSS_HOME/modules/org/springframework/spring/main) which needs to be at first created, and adding its module.xml descriptor. Below is an example of the Spring module.xml, containing the name of jars referenced in the resourceroot paths, which must match the actual name of the jars in the module:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.springframework.spring">
   <resources>
      <resource-root path="spring-core.jar" />
      <resource-root path="spring-beans.jar" />
      <resource-root path="spring-jms.jar" />
      <resource-root path="spring-context.jar" />
      <resource-root path="spring-asm.jar" />
      <resource-root path="spring-expression.jar" />
      <resource-root path="spring-tx.jar" />
      <resource-root path="spring-aop.jar" />
   </resources>
   <dependencies>
      <module name="javax.api" />
      <module name="javax.jms.api" />
      <module name="javax.annotation.api" />
      <module name="org.apache.commons.logging" />
      <module name="org.jboss.vfs" />
   </dependencies>
</module>

When Spring is available, the creation of Apache CXF Bus instances will load cxf.xml descriptor resources that can be found using the current thread classloader.

On server side, when the org.springframework.spring module is properly configured, JBossWS processes a custom descriptor, which can be added to the Web Services deployments. The convention for such a descriptor is the following:

  • The descriptor file name must be jbossws-cxf.xml
  • This descriptor is located in WEB-INF directory for POJO deployments
  • This descriptor is located in META-INF for EJB3 deployments

Here is an example of jbossws-cxf.xml, which contains an endpoint definition:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
   <jaxws:endpoint id="SampleWS" address="http://localhost:8080/Samplews" implementor="com.sample.SampleWS">
      <jaxws:invoker>
         <bean class="org.jboss.wsf.stack.cxf.JBossWSInvoker" />
      </jaxws:invoker>
   </jaxws:endpoint>
</beans>

Once loaded the jbossws-cxf.xml, the WildFly HTTP engine will be serving the endpoints.

Do you want some more Spring stuff ? check Spring Boot Tutorials !

Found the article helpful? if so please follow us on Socials