The AspectJPrecedenceComparator was designed to mimic the precedence order enforced by the AspectJ compiler with regard to multiple 'after' methods defined within the same aspect whose pointcuts match the same joinpoint. Specifically, if an aspect declares multiple @After, @AfterReturning, or @AfterThrowing advice methods whose pointcuts match the same joinpoint, such 'after' advice methods should be invoked in the reverse order in which they are declared in the source code. When the AspectJPrecedenceComparator was introduced in Spring Framework 2.0, it achieved its goal of mimicking the AspectJ compiler since the JDK at that time (i.e., Java 5) ensured that an invocation of Class#geDeclaredMethods() returned an array of methods that matched the order of declaration in the source code. However, Java 7 removed this guarantee. Consequently, in Java 7 or higher, AspectJPrecedenceComparator no longer works as it is documented or as it was designed when sorting advice methods in a single @Aspect class. Note, however, that AspectJPrecedenceComparator continues to work as documented and designed when sorting advice configured via the <aop:aspect> XML namespace element. PR gh-24673 highlights a use case where AspectJPrecedenceComparator fails to assign the highest precedence to an @After advice method declared last in the source code. Note that an @After advice method with a precedence higher than @AfterReturning and @AfterThrowing advice methods in the same aspect will effectively be invoked last due to the try-finally implementation in AspectJAfterAdvice.invoke() which invokes proceed() in the try-block and invokeAdviceMethod() in the finally-block. Since Spring cannot reliably determine the source code declaration order of annotated advice methods without using ASM to analyze the byte code, this commit introduces reliable invocation order for advice methods declared within a single @Aspect. Specifically, the getAdvisors(...) method in ReflectiveAspectJAdvisorFactory now hard codes the declarationOrderInAspect to `0` instead of using the index of the current advice method. This is necessary since the index no longer has any correlation to the method declaration order in the source code. The result is that all advice methods discovered via reflection will now be sorted only according to the precedence rules defined in the ReflectiveAspectJAdvisorFactory.METHOD_COMPARATOR. Specifically, advice methods within a single @Aspect will be sorted in the following order (with @After advice methods effectively invoked after @AfterReturning and @AfterThrowing advice methods): @Around, @Before, @After, @AfterReturning, @AfterThrowing. The modified assertions in AspectJAutoProxyAdviceOrderIntegrationTests demonstrate the concrete effects of this change. Closes gh-25186 |
||
|---|---|---|
| .github | ||
| buildSrc | ||
| framework-bom | ||
| gradle | ||
| integration-tests | ||
| spring-aop | ||
| spring-aspects | ||
| spring-beans | ||
| spring-context | ||
| spring-context-indexer | ||
| spring-context-support | ||
| spring-core | ||
| spring-expression | ||
| spring-instrument | ||
| spring-jcl | ||
| spring-jdbc | ||
| spring-jms | ||
| spring-messaging | ||
| spring-orm | ||
| spring-oxm | ||
| spring-test | ||
| spring-tx | ||
| spring-web | ||
| spring-webflux | ||
| spring-webmvc | ||
| spring-websocket | ||
| src | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| .mailmap | ||
| CODE_OF_CONDUCT.adoc | ||
| CONTRIBUTING.md | ||
| LICENSE.txt | ||
| README.md | ||
| SECURITY.md | ||
| build.gradle | ||
| gradle.properties | ||
| gradlew | ||
| gradlew.bat | ||
| import-into-eclipse.md | ||
| import-into-idea.md | ||
| settings.gradle | ||
README.md
Spring Framework 
This is the home of the Spring Framework: the foundation for all Spring projects. Collectively the Spring Framework and the family of Spring projects are often referred to simply as "Spring".
Spring provides everything required beyond the Java programming language for creating enterprise applications for a wide range of scenarios and architectures. Please read the Overview section as reference for a more complete introduction.
Code of Conduct
This project is governed by the Spring Code of Conduct. By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to spring-code-of-conduct@pivotal.io.
Access to Binaries
For access to artifacts or a distribution zip, see the Spring Framework Artifacts wiki page.
Documentation
The Spring Framework maintains reference documentation (published and source), Github wiki pages, and an API reference. There are also guides and tutorials across Spring projects.
Build from Source
See the Build from Source Wiki page and the CONTRIBUTING.md file.
Stay in Touch
Follow @SpringCentral, @SpringFramework, and its team members on Twitter. In-depth articles can be found at The Spring Blog, and releases are announced via our news feed.
License
The Spring Framework is released under version 2.0 of the Apache License.