Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring事务回滚不起作用_Java_Spring - Fatal编程技术网

Java Spring事务回滚不起作用

Java Spring事务回滚不起作用,java,spring,Java,Spring,我有下面的线程和事务方法,我抛出了一个异常来测试DB插入的回滚,但并没有改变任何东西。我错过了什么 public class CleaningThread extends Thread { public void run() { try { doJob(); } catch (Exception e) { e.printStackTrace(); } } @Transact

我有下面的线程和事务方法,我抛出了一个异常来测试DB插入的回滚,但并没有改变任何东西。我错过了什么

public class CleaningThread extends Thread {

   public void run() {
        try {
            doJob();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

     @Transactional(rollbackFor=Exception.class)
    private void doJob() throws Exception {

    //INSERT OPERATION
     final BatchSqlUpdate bs = new BatchSqlUpdate
     bs.flush()

     throw new Exception("Custom exception")

    //UPDATE

    }

    }
应用程序上下文:

 <tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/>

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>file:conf/offclear.properties</value>
        </list>
    </property>
</bean>

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
</bean>

<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
</bean>

<bean id="cleaningThread" class="CleaningThread" scope="prototype"/>

文件:conf/offclear.properties

使用Spring3.1,您正在从同一类的方法run()调用方法doJob()。这就是为什么您使用的是实方法,而不是代理方法


实际上,这个问题在本主题中已经讨论过:

您正在从同一类的方法run()调用方法doJob()。这就是为什么您使用的是实方法,而不是代理方法


实际上,这个问题在本主题中已经讨论过:

。一个解决方案是自动连线,然后调用myThread.doJob()-正如您所看到的,我使用的是prototype作用域,哪个实例将自动连线?。一个解决方案是自动连线,然后调用myThread.doJob()-如您所见,我正在使用prototype scope,哪个实例将自动连接?