Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring Transaction Manager
    text
    copied!<p>I have a j2ee application running on spring framework. I am implementing a transaction manager with AOP. It works fine.<br> When an exception occurs in my method it is detected by my AOP configuration and rolls back the changes in the DB. But the problem is the code where you expect the error should not be surrounded with try-catch. When I surround it with try-catch it won't roll-back. But I need to do some stuffs like logging whenever there are errors and the only place I can think of placing it is in the catch block.</p> <pre><code>public class RegisterGLogic implements BLogic { public BLogicResult execute() { BLogicResult result = new BLogicResult(); //do some db operation return result; } } </code></pre> <p>here's my AOP transaction configuration</p> <pre><code>&lt;bean id="TerasolunaDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt; &lt;property name="jndiName" value="PrototypeDataSource" /&gt; &lt;/bean&gt; &lt;tx:advice id="transactionInterceptor" transaction-manager="transactionManager"&gt; &lt;tx:attributes&gt; &lt;tx:method name="insert*" propagation="REQUIRED" rollback-for="java.lang.Exception" /&gt; &lt;tx:method name="execute*" propagation="REQUIRED" rollback-for="java.lang.Exception" /&gt; &lt;tx:method name="*" propagation="REQUIRED" read-only="true" /&gt; &lt;/tx:attributes&gt; &lt;/tx:advice&gt; &lt;!-- AOPの設定 --&gt; &lt;aop:config&gt; &lt;aop:pointcut id="blogicBeans" expression="bean(*BLogic)" /&gt; &lt;aop:pointcut id="serviceBeans" expression="bean(*Service)" /&gt; &lt;aop:advisor pointcut-ref="blogicBeans" advice-ref="transactionInterceptor" /&gt; &lt;aop:advisor pointcut-ref="serviceBeans" advice-ref="transactionInterceptor" /&gt; &lt;/aop:config&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload