I am currently working on upgrading my Spring Boot application from version 3.2 to 3.3. The application utilizes AspectJ for handling transactions, specifically with @EnableTransactionManagement(mode = AdviceMode.ASPECTJ). This setup is crucial because the transactional methods are self-invoked, which is not supported with the default proxy mode.
After upgrading to Spring Boot 3.3, I encountered issues with @Transactional not functioning as expected. My project uses the JCABI Aspect Plugin, and the logs show the following errors related to @Transactional methods:
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')
I downgraded the Micrometer dependency to 1.12.13, which is the version used in Spring Boot 3.2, and the application started working fine with Spring Boot 3.3. However, I would prefer to resolve this issue by replacing the JCABI Plugin with an up-to-date alternative.
Currently, I am facing the following error:
jakarta.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call
Additionally, I have not been able to find a way to export the logs to a file. During the Maven build, the logs are printed, but I do not see any weaving logs for my transactional methods.
Questions: How can I resolve the jakarta.persistence.TransactionRequiredException error? Is there a way to enable and export detailed AspectJ weaving logs?
Any insights or guidance on these issues would be greatly appreciated. Thank you!
Link to MVCe: https://github.com/GeneralNitin/Spring-Aspect-Tx.
Please check the pull requests to see the changes I have done so far.
I fixed your problems in this PR. Transaction management was not working, because neither did you configure the application to run with native AspectJ via load-time weaving nor did you include spring-aspects
in compile-time weaving. Micrometer needed an upgrade, not a downgrade, because 1.14.x contains a fix for invalid pointcut syntax detected by me a while ago. I suggested a fix that was included in the product.
Quoting the PR description:
Migrate to AspectJ Maven, fix Spring transactions and Micrometer pointcut error
- Fix Spring native AspectJ transactions by using
spring-aspects
as an AspectJ Maven weave dependency.- Reproduce the Micrometer "invalid pointcut" problem. Fix it by upgrading Micrometer version. The problem was fixed as part of Compile-time weaving support for aspects micrometer-metrics/micrometer#1149, see my own comment Compile-time weaving support for aspects micrometer-metrics/micrometer#1149 (comment) suggesting the fix.