Configuration for Transaction Management [Spring/Java]


I would like to share some configuration for transaction management in Spring Framework.

🍮 Set transaction automatically

It is a configuration to set @Transactional under webapp.sample.service package hierarchy.


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">


<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" isolation="READ_COMMITTED" />
tx:attributes>
tx:advice>

<aop:config>

<aop:advisor pointcut="execution(public * com.m3.hqmr.service..*.*(..)) and @target(org.springframework.stereotype.Service)" advice-ref="txAdvice" />
aop:config>

beans>

This configuration uses AOP(Aspect Oriented Programming) which is adding new processing without changing original source.
AOP is a mechanism for “cross-cutting issue” such as outputting trace log, managing transaction or etc.

🍄 References

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!