Vegard
Vegard

Reputation: 1932

Springs @Transactional only works for proxy

I have a method that uses Springs @Transactional for database rollbacks. It works fine when i define the transaction manager like this:

    <tx:annotation-driven transaction-manager="txManager" mode="proxy" />

but when i change to mode="aspectj" it does not rollback when the method throws an exception.

are there some differences in how the two modes should be used?

Upvotes: 4

Views: 1200

Answers (1)

Reimeus
Reimeus

Reputation: 159784

The "aspectj" mode will only work if load-time weaving or compile-time weaving are enabled. If not then the @Transactional annotation will not be applied to the annotated method.

The default proxy mode cannot be used to annotate private methods. This is where aspectj mode is useful. Certain frameworks (such as W2O for Web Services) require the class type itself to work. This can be impossible using proxy mode as the class is wrapped in a proxy class wrapper. This is another reason for using AspectJ.

If public methods are used and there are no special framework restrictions, then proxy mode is sufficient.

See Also: Transaction Management

Upvotes: 1

Related Questions