Java Reference
In-Depth Information
public class FrontDeskImpl extends JmsGatewaySupport implements FrontDesk {
@Transactional
public void sendMail(Mail mail) {
...
}
}
package com.apress.springenterpriserecipes.post;
import org.springframework.jms.core.support.JmsGatewaySupport;
import org.springframework.transaction.annotation.Transactional;
...
public class BackOfficeImpl extends JmsGatewaySupport implements BackOffice {
@Transactional
public Mail receiveMail() {
...
}
}
Then, in both bean configuration files, you add the
<tx:annotation-driven />
element and
declare a transaction manager. The corresponding transaction manager for local JMS transactions is
JmsTransactionManager
, which requires a reference to the JMS connection factory.
<beans xmlns="
http://www.springframework.org/schema/beans"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="
http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
...
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory">
<ref bean="connectionFactory" />
</property>
</bean>
</beans>
If you require transaction management across multiple resources, such as a data source and an
ORM resource factory, or if you need distributed transaction management, you have to configure JTA
transaction in your application server and use
JtaTransactionManager
. Of course, your JMS connection
factory must be XA compliant (i.e., supporting distributed transactions).
Search WWH ::
Custom Search