gpt4 book ai didi

java - Spring Boot @EnableTransactionManagement(mode = AdviceMode.ASPECTJ) 不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 09:57:27 25 4
gpt4 key购买 nike

当我尝试使用时:

@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)

交易不起作用,但如果我使用

@EnableTransactionManagement(mode = AdviceMode.PROXY)

一切正常。

我的代码:

SpringBoot应用

@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());
}
}

我还有一个 VM 选项:-javaagent:"spring-instrument-5.1.2.RELEASE.jar"for ASPECTJ。

这是我在尝试获取当前交易时接受的异常。

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

也是我的依靠

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 应该可以解决您的问题。

关于java - Spring Boot @EnableTransactionManagement(mode = AdviceMode.ASPECTJ) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53931934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com