How to use transaction advisors with annotations?
supose I have the following example:
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public class MyServiceImpl implements MyService {
...
@Transactional(propagation=Propagation.REQUIRED, readOnly=false)
public TransactionResponse addMyEntity(MyEntity e) throws SQLException{
...
}
...
}
And in my applicationC开发者_开发百科ontext:
<tx:annotation-driven transaction-manager="txManager" />
Ok, now I want to add an interceptor after the rollback of the transaction if an SQLException is thrown. How can I do this?
Thanks in advance
EDIT
I'll try to clarify what I'm trying to do:
I have a WS, that persists some information on a DB and returns a response (an isOk boolean and an errorMessage if something went wrong)
Whenever an exception is risen, I need to:
- Rollback the transaction
- Build the response with the error message and return it to the client.
It's like a try/catch around spring's transaction proxy
Use the order
attribute of tx:annotation-driven
, and of the interceptor you will be using. Thus you specify which one runs before the other. See the AOP AspectJ advice ordering section
精彩评论