Spring Boot 升级到 3.3:@Transactional 和 AspectJ Weaving 的问题

问题描述 投票:0回答:1

我目前正在努力将我的 Spring Boot 应用程序从版本 3.2 升级到 3.3。该应用程序利用 AspectJ 来处理事务,特别是使用 @EnableTransactionManagement(mode = AdviceMode.ASPECTJ)。此设置至关重要,因为事务方法是自调用的,默认代理模式不支持此功能。

升级到 Spring Boot 3.3 后,我遇到了 @Transactional 无法按预期运行的问题。我的项目使用 JCABI Aspect Plugin,日志显示以下与 @Transactional 方法相关的错误:

Tue Jan 14 02:13:41 IST 2025
io/micrometer/observation/aop/ObservedAspect.java [error] Invalid pointcut '@within(io.micrometer.observation.annotation.Observed) and not @annotation(io.micrometer.observation.annotation.Observed)': org.aspectj.weaver.patterns.ParserException: unexpected pointcut element: and@55:57 at position 55
    
<Unknown> [warning] Found @DeclareAnnotation while current release does not support it (see 'org.aspectj.weaver.bcel.AtAjAttributes')
    
io/micrometer/observation/aop/ObservedAspect.java [error] Invalid pointcut '@within(io.micrometer.observation.annotation.Observed) and not @annotation(io.micrometer.observation.annotation.Observed)': org.aspectj.weaver.patterns.ParserException: unexpected pointcut element: and@55:57 at position 55
    
<Unknown> [warning] Found @DeclareAnnotation while current release does not support it (see 'org.aspectj.weaver.bcel.AtAjAttributes')
    

我将 Micrometer 依赖项降级到 1.12.13,这是 Spring Boot 3.2 中使用的版本,并且应用程序开始在 Spring Boot 3.3 中正常工作。但是,我更愿意通过使用最新的替代方案替换 JCABI 插件来解决此问题。

目前,我面临以下错误:

jakarta.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call

此外,我还没有找到将日志导出到文件的方法。在 Maven 构建期间,会打印日志,但我没有看到我的事务方法的任何编织日志。

问题: 如何解决 jakarta.persistence.TransactionRequiredException 错误? 有没有办法启用并导出详细的 AspectJ 编织日志?

任何有关这些问题的见解或指导将不胜感激。谢谢!

MVCe 链接:https://github.com/GeneralNitin/Spring-Aspect-Tx

请检查拉取请求以查看我迄今为止所做的更改。

spring-boot aspectj
1个回答
0
投票

我在此 PR 中解决了您的问题。事务管理不起作用,因为您既没有通过加载时编织将应用程序配置为与本机 AspectJ 一起运行,也没有在编译时编织中包含

spring-aspects
。 Micrometer 需要升级,而不是降级,因为 1.14.x 包含对我不久前检测到的无效切入点语法的修复。我建议了产品中包含的修复程序。

引用PR描述:

迁移到 AspectJ Maven,修复 Spring 事务和 Micrometer 切入点错误

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.