Java Reference
In-Depth Information
java -javaagent: spring-instrument.jar
To enable transaction management for a domain object's method, you can simply annotate it with
@Transactional , just as you did for methods of Spring beans.
package com.apress.springenterpriserecipes.bookshop.aspectj;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.transaction.annotation.Transactional;
public class Book {
public void purchase(String username) {
Finally, to enable Spring's AnnotationTransactionAspect for transaction management, you just
define the <tx:annotation-driven> element and set its mode to aspectj . The <tx:annotation-driven>
element takes two values for the mode attribute: aspectj and proxy . aspect stipulates that the container
should use load-time or compile-time weaving to enable the transaction advice. This requires the
spring-aspects jar to be on the classpath, as well as the appropriate configuration at load time or
compile time. Alternatively, proxy stipulates that the container should use the Spring AOP mechanisms.
It's important to note that the aspect mode doesn't support configuration of the @Transactional
annotation on interfaces. Then the transaction aspect will automatically get enabled. You also have to
provide a transaction manager for this aspect. By default, it will look for a transaction manager whose
name is transactionManager .
<beans xmlns= " "
xmlns:xsi= " "
xmlns:context= " "
xmlns:tx= " "
xsi:schemaLocation= " " >
<tx:annotation-driven mode= " aspectj " />
<bean id= " transactionManager "
class= " org.springframework.jdbc.datasource.DataSourceTransactionManager " >
<property name= " dataSource " ref= " dataSource " />
Search WWH ::

Custom Search