What does aop.xml File in Spring-Aspects Artifact?

110 views Asked by At

I activated aspectj load time weaving for my application and added an aop.xml file defining my aspects.

I found out that the spring-aspects jar on my classpath does contain an aop.xml file too and is loaded when I configure my application to start with the aspectjweaver.jar as java agent.

It seems, that this file is unused, when no weaving is activated but does increase the application startup time when activated. What is this file used for?

1

There are 1 answers

9
kriegaex On

You are talking about this file. Quoting its content, slightly reformatted:

<?xml version="1.0"?>
<!-- AspectJ load-time weaving config file to install common Spring aspects. -->
<aspectj>
  <!--<weaver options="-showWeaveInfo"/>-->
  <aspects>
    <aspect name="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"/>
    <aspect name="org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect"/>
    <aspect name="org.springframework.transaction.aspectj.AnnotationTransactionAspect"/>
    <aspect name="org.springframework.transaction.aspectj.JtaAnnotationTransactionAspect"/>
    <aspect name="org.springframework.cache.aspectj.AnnotationCacheAspect"/>
    <aspect name="org.springframework.cache.aspectj.JCacheCacheAspect"/>
  </aspects>
</aspectj>

Firstly, talking about spring-aspects, you need to understand that it uses native AspectJ, not proxy-based Spring AOP. The technique used to weave aspects is called load-time weaving (LTW), i.e. target class byte code gets transformed during class-loading by a weaving agent that usually is added to the JVM command line like this:

java ... -javaagent:/my/aspectjweaver.jar -javaagent:/my/spring-aspects.jar

You see, you can use a single or even multiple agents at the same time. This is a generic, standardised JVM mechanism. AspectJ simply happens to use it, like many other Java agents do.

There is a chapter in the Spring manual, describing how to use native AspectJ in Spring. One brief paragraph deals with aop.xml, pointing further to the corresponding AspectJ manual chapter.

In a nutshell:

  • AspectJ LTW is configurable. The way you configure it is an aop.xml file.
  • spring-aspects therefore comes with its own aop.xml file. It lists the currently six (6) aspects contained within the library.