Using the JMSConfigFeature
Standard JMS transport configuration in CXF is done by defining a JMSConduit or JMSDestination. There is however an easier configuration option more conformant to Spring dependency injection. Additionally the new configuration offers many more options. For example it is not necessary anymore to use JNDI to resolve the connection factory. Instead it can be defined in the Spring configuration.
The following example configs use the p-namespace from Spring 2.5 but the old Spring bean style is also possible.
Inside a features element the JMSConfigFeature can be defined.
<jaxws:client id="CustomerService"
xmlns:customer="http://customerservice.example.com/"
serviceName="customer:CustomerServiceService"
endpointName="customer:CustomerServiceEndpoint" address="jms://"
serviceClass="com.example.customerservice.CustomerService">
<jaxws:features>
<bean xmlns="http://www.springframework.org/schema/beans"
class="org.apache.cxf.transport.jms.JMSConfigFeature"
p:jmsConfig-ref="jmsConfig"/>
</jaxws:features>
</jaxws:client>
In the above example it references a bean "jmsConfig" where the whole configuration for the JMS transport can be done.
A jaxws Endpoint can be defined in the same way:
<jaxws:endpoint
xmlns:customer="http://customerservice.example.com/"
id="CustomerService"
address="jms://"
serviceName="customer:CustomerServiceService"
endpointName="customer:CustomerServiceEndpoint"
implementor="com.example.customerservice.impl.CustomerServiceImpl">
<jaxws:features>
<bean class="org.apache.cxf.transport.jms.JMSConfigFeature"
p:jmsConfig-ref="jmsConfig" />
</jaxws:features>
</jaxws:endpoint>
The JMSConfiguration bean needs at least a reference to a connection factory and a target destination.
<bean id="jmsConfig" class="org.apache.cxf.transport.jms.JMSConfiguration"
p:connectionFactory-ref="jmsConnectionFactory"
p:targetDestination="test.cxf.jmstransport.queue"
/>
If your ConnectionFactory does not cache connections you should wrap it in a Spring SingleConnectionFactory. This is necessary because the JMS Transport creates a new connection for each message and the SingleConnectionFactory is needed to cache this connection.
<bean id="jmsConnectionFactory"
class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
</property>
</bean>