Created
July 26, 2012 13:04
-
-
Save rponte/3181934 to your computer and use it in GitHub Desktop.
Mixing Spring AOP Declarative Transaction with @transactional
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:context="http://www.springframework.org/schema/context" | |
xmlns:aop="http://www.springframework.org/schema/aop" | |
xmlns:tx="http://www.springframework.org/schema/tx" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans | |
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd | |
http://www.springframework.org/schema/context | |
http://www.springframework.org/schema/context/spring-context-3.0.xsd | |
http://www.springframework.org/schema/tx | |
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd | |
http://www.springframework.org/schema/aop | |
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> | |
<context:annotation-config /> | |
<context:component-scan base-package="br.com.triadworks" /> | |
<!-- habilita suporte as anotações transacionais --> | |
<tx:annotation-driven order="1" /> | |
<!-- the transactional advice (what 'happens'; see the <aop:advisor/> bean below) --> | |
<tx:advice id="txAdvice"> | |
<!-- the transactional semantics... --> | |
<tx:attributes> | |
<!-- all methods starting with 'get' are read-only --> | |
<tx:method name="find*" read-only="true" /> | |
<tx:method name="count*" read-only="true" /> | |
<tx:method name="get*" read-only="true" /> | |
<tx:method name="busca*" read-only="true" /> | |
<tx:method name="lista*" read-only="true" /> | |
<!-- other methods use the default transaction settings (see below) --> | |
<tx:method name="*" propagation="REQUIRED" /> | |
</tx:attributes> | |
</tx:advice> | |
<!-- Configuração do Aspecto das transações. --> | |
<aop:config> | |
<aop:pointcut id="serviceMethods" | |
expression="execution(* br.com.syspdv.triadworks..*.*(..)) | |
and not @annotation(org.springframework.transaction.annotation.Transactional)" /> | |
<aop:advisor order="2" advice-ref="txAdvice" | |
pointcut-ref="serviceMethods" /> | |
</aop:config> | |
</beans> |
you could add and not within(@org.springframework.transaction.annotation.Transactional *)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The real magic is in the pointcut expression:
and not @annotation(org.springframework.transaction.annotation.Transactional)
- but probably this only works on a method annotated with @transactional, not a class/type.