Aspects are being executed twice since Spring Framework 6.1.7
search cancel

Aspects are being executed twice since Spring Framework 6.1.7

book

Article ID: 382018

calendar_today

Updated On:

Products

VMware Tanzu Spring Runtime

Issue/Introduction

Spring Framework 6.1.7 introduces a significant change in how "@Aspect classes" are handled. This change aligns with recommendations from the AspectJ maintainer, emphasizing the proper compilation of reusable AspectJ aspects.

Previously, Spring AOP ignored compiled AspectJ aspects. With the new update, Spring AOP no longer does so by default, leading to potential conflicts when certain configurations are used together.

With Spring auto-proxying active (enabled by default in Spring Boot), any @Aspect class exposed as a Spring bean will be considered for AOP proxying.

If an aspect is intended only for ajc compilation (e.g., using the AspectJ Maven plugin), ensure that:

  • Boot's auto-proxying auto-configuration is disabled.
  • The AspectJ-managed aspect is not exposed as a Spring bean.

Potential Conflicts:
Applications combining AspectJ weaving and @EnableAspectJAutoProxy while exposing AspectJ aspects as Spring-managed beans may encounter issues.
In Spring Boot, auto-proxying is enabled by default when AspectJ is on the classpath, even if weaving is used. This behavior can lead to unexpected conflicts.

Environment

Spring-Framework 6.1.7 

Resolution

As a workaround for this issue versions v6.1.15, v6.0.26 have the possibility to add as a system property or as a spring.properties file: 

"spring.aop.ajc.ignore=true"