How does Spring container handle the bean / config-tags specification
Joined: Jun 01, 2011
regarding Spring management of tags defined in applicationContext-xml.
haven't written the xmlns and aop schemaLocation in the question deliberately for you to read with ease...
example xml :- ( AOP using autoproxy tag )
Both TransactionAspect and LoggingAspect are mentioned as @Before ( using annotations ) and since the Transaction appears first in the XML followed by the Log, the TXN advice will be weaved first and then the Log..
I could specify the order of aspects using @Order but my question is about the xml way..
the autoproxy tag could be anywhere, but the order of Aspect specification was important..how does the Spring parses / transforms the xml to recognize the config tags like or differently and the user mentioned beans/ aspects differently ?
P.S :- please ignore any code mistakes, my question is only about the ordering and how Spring manages it...
No specified ordering means that the AOP subsystem determines the order of the advice.
Long answer from the spring documentation:
What happens when multiple pieces of advice all want to run at the same join point? Spring AOP follows
the same precedence rules as AspectJ to determine the order of advice execution. The highest precedence
advice runs first "on the way in" (so given two pieces of before advice, the one with highest precedence
runs first). "On the way out" from a join point, the highest precedence advice runs last (so given two
pieces of after advice, the one with the highest precedence will run second).
When two pieces of advice defined in different aspects both need to run at the same join point, unless you
specify otherwise the order of execution is undefined. You can control the order of execution by
specifying precedence. This is done in the normal Spring way by either implementing the
org.springframework.core.Ordered interface in the aspect class or annotating it with the
Order annotation. Given two aspects, the aspect returning the lower value from
Ordered.getValue() (or the annotation value) has the higher precedence.
When two pieces of advice defined in the same aspect both need to run at the same join point, the
ordering is undefined (since there is no way to retrieve the declaration order via reflection for
javac-compiled classes). Consider collapsing such advice methods into one advice method per join point
in each aspect class, or refactor the pieces of advice into separate aspect classes - which can be ordered at
the aspect level.