Java Reference
In-Depth Information
<bean id= " bookShop "
class= " com.apress.springenterpriserecipes.bookshop.spring.
TransactionalJdbcBookShop " >
<property name= " dataSource " ref= " dataSource " />
<property name= " transactionTemplate " ref= " transactionTemplate " />
</bean>
</beans>
4-5. Managing Transactions Declaratively with Transaction
Advices
Problem
Because transaction management is a kind of crosscutting concern, you should manage transactions
declaratively with the AOP approach available from Spring 2.x onward.
Solution
Spring (since version 2.0) offers a transaction advice that can be easily configured via the <tx:advice>
element defined in the tx schema. This advice can be enabled with the AOP configuration facilities
defined in the aop schema.
How It Works
To enable declarative transaction management, you can declare a transaction advice via the <tx:advice>
element defined in the tx schema, so you have to add this schema definition to the <beans> root element
beforehand. Once you have declared this advice, you need to associate it with a pointcut. Because a
transaction advice is declared outside the <aop:config> element, it cannot link with a pointcut directly.
You have to declare an advisor in the <aop:config> element to associate an advice with a pointcut.
Note Because Spring AOP uses the AspectJ pointcut expressions to define pointcuts, you have to include
aspectjweaver.jar (located in the lib/aspectj directory of the Spring installation) in your classpath. If you're
using Maven, then the dependency is as follows:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.2</version>
</dependency>
 
Search WWH ::




Custom Search