是否可以在Spring中从非事务方法调用事务方法?

Joh*_*ter 5 java spring

假设我有一个Repository类.

@Repository
class MyRepository {

    @Transactional
    void method1 () {
        // some logic here
    }

    void method2 () {
        // some logic here
        method1();
        // some logic here
    }
}
Run Code Online (Sandbox Code Playgroud)

在String中可以这样做吗?这是如何工作的?

use*_*547 5

这不起作用,因为这是一个自我调用.通过同一个类中的方法查看
Spring @Transaction方法调用,不起作用?

根据您的应用程序及其职责,您可以为其创建另一个bean method2().除此之外,DAO方法通常不应注释@Transactional.请参阅
@Transactional注释所属的位置?