Java Reference
In-Depth Information
In Spring's transaction management API, the timeout and read-only transaction attributes can
be specified in a DefaultTransactionDefinition object and then passed to a transaction manager's
getTransaction() method or a transaction template's constructor.
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setTimeout( 30);
def.setReadOnly( true);
4-11. Managing Transactions with Load-Time Weaving
By default, Spring's declarative transaction management is enabled via its AOP framework. However,
as Spring AOP can only advise public methods of beans declared in the IoC container, you are restricted
to managing transactions within this scope using Spring AOP. Sometimes you may wish to manage
transactions for non-public methods, or methods of objects created outside the Spring IoC container
(e.g., domain objects).
Spring 2.5 also provides an AspectJ aspect named AnnotationTransactionAspect that can manage
transactions for any methods of any objects, even if the methods are non-public or the objects are
created outside the Spring IoC container. This aspect will manage transactions for any methods with the
@Transactional annotation. You can choose either AspectJ's compile-time weaving or load-time weaving
to enable this aspect.
How It Works
First of all, let's create a domain class Book , whose instances (i.e., domain objects) may be created
outside the Spring IoC container.
package com.apress.springenterpriserecipes.bookshop.aspectj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.jdbc.core.JdbcTemplate;
public class Book {
private String isbn;
private String name;
private int price;
// Constructors, Getters and Setters
Search WWH ::

Custom Search