简体   繁体   中英

Spring Boot @EnableTransactionManagement(mode = AdviceMode.ASPECTJ) dont work

When i try to use:

@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)

transaction not working, but if i use

@EnableTransactionManagement(mode = AdviceMode.PROXY)

everything works fine.

My code:

SpringBootAplication

@SpringBootApplication
@EnableScheduling
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
public class SpringBootAplication
{
    private static ConfigurableApplicationContext applicationContext;


    public static void main(String[] args)
    {              System.out.println(InstrumentationLoadTimeWeaver.isInstrumentationAvailable());
        applicationContext = SpringApplication.run(SpringBootAplication.class, args);
    }

Controller

@RestController
public class MyController
{
    @Autowired
    MyRepository repository;

    @Transactional
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public void test()
    {
        repository.findById("name");
        System.out.println(TransactionAspectSupport.currentTransactionStatus());
    }
}

Also i have a VM options: -javaagent:"spring-instrument-5.1.2.RELEASE.jar" for ASPECTJ.

And this is exception which i accept when try to get current transaction.

org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope

Also my depend

implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-thymeleaf')
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation("org.springframework.boot:spring-boot-starter-websocket")
implementation('org.springframework.boot:spring-boot-starter-security')
implementation("org.springframework.boot:spring-boot-devtools")

添加aspectjweaver.jar代理: -javaagent:/path/to/aspectjweaver.jar应该可以解决您的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM