For Spring Framework Version 2.5 or later, you can use the declarative transaction model, use the Spring Framework support for the AspectJ programming extension, or use annotation-based transaction support. For versions of the Spring Framework earlier than Version 2.5, and for versions of the application server that do not provide the UOWManager interface, you can use a Spring Framework configuration that supports a restricted set of transaction attributes.
WebSphere® Application Server Version 6.0.2.19 or later and Version 6.1.0.9 or later support the Spring Framework declarative transaction model to drive resource updates under transactional control. The WebSphereUowTransactionManager class in Spring Framework 2.5 uses the UOWManager interface in the application server to manage the transaction context. Because transaction demarcation is managed through the UOWManager interface, an appropriate global transaction or local transaction containment (LTC) context is always available when a resource provider is accessed. For more information about the UOWManager interface and Java™ Transaction API (JTA) support, see the related topic.
<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>
<bean id="someBean" class="some.class"> <property name="transactionManager" > <ref bean="transactionManager"/> </property> ... </bean> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property>
<tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" propagation="REQUIRED" read-only="true" /> <tx:method name="set*" propagation="REQUIRES_NEW" /> <tx:method name="*" /> </tx:attributes> </tx:advice>
<aop:config> <aop:pointcut id="myServiceOperation" expression="execution(* sample.service.MyService.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="myServiceOperation"/> </aop:config>
To use the annotation-based transaction support, you need Java Platform, Standard Edition 5 (Java SE 5) or later. Therefore, you can use this method with WebSphere Application Server Version 6.1 or later.
<tx:annotation-driven/>
@Transactional(readOnly = true) public String getUserName() { ... }
You can use the @Transactional annotation to annotate only public methods.
You can use a Spring Framework configuration that supports a restricted set of transaction attributes.
You can use this method of transaction support with versions of the Spring Framework before Version 2.5 that do not provide the WebSphereUowTransactionManager class. You can also use this method of transaction support with versions of WebSphere Application Server earlier than Version 6.0.2.19 and Version 6.1.0.9 that do not provide the UOWManager interface.
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="autodetectTransactionManager"value="false" /> </bean>
WebSphere Application Server does not support the use of the Spring Framework class org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean.