Skip to content

Instantly share code, notes, and snippets.

@jpukg
Forked from tsegismont/gist:2960038
Created April 13, 2018 21:40
Show Gist options
  • Save jpukg/17af1e8ec3fd5f83c2d3d19d2bc3d572 to your computer and use it in GitHub Desktop.
Save jpukg/17af1e8ec3fd5f83c2d3d19d2bc3d572 to your computer and use it in GitHub Desktop.
Default Transaction Interception for spring @service objects
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="myDS" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<aop:config>
<aop:pointcut id="defaultServiceMethodTxPointcut"
expression="execution([email protected] * *(..))
and @within(org.springframework.stereotype.Service)
and (!@within(org.springframework.transaction.annotation.Transactional)) " />
<aop:advisor advice-ref="defaultServiceMethodTxAdvice" pointcut-ref="defaultServiceMethodTxPointcut" />
</aop:config>
<tx:advice id="defaultServiceMethodTxAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
<tx:method name="is*" propagation="SUPPORTS" read-only="true" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="load*" propagation="SUPPORTS" read-only="true" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment