Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Spring AOP do compile time weaving or load time weaving?

I am starting to use Spring AOP for a project and I am a little bit confused about weaving. I know that Spring AOP has a dependency on AspectJweaver.jar, but as the documentation says, this is not for the weaving, but just that it uses some of the classes from this jar.

But my question is, if it is not using AspectJ for weaving, does Spring AOP have its own weaving and is it performed at load time or compile time?

The relevant part of my Spring Configuration XML file is:

<context:annotation-config />

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="get*" read-only="true" />
        <tx:method name="*" />
    </tx:attributes>
</tx:advice>

<aop:config>
    <aop:pointcut id="myaop" expression="execution(* my.package.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="myaop" />
</aop:config>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>
like image 878
DaveJohnston Avatar asked Feb 04 '14 10:02

DaveJohnston


2 Answers

An update who is reading this in 2019 and probably later:

In spring 5.x aspectjweaver.jar was removed as a dependency and there is a need to include it separately if you want to use @AspectJ style annotations (or use Spring Boot for example).

  • Spring 5.x POM (doesn't include)
  • Spring 4.x POM (does include)

Weaving principles stay the same though - documentation

like image 50
skryvets Avatar answered Nov 10 '22 20:11

skryvets


http://docs.spring.io/spring/docs/4.0.1.RELEASE/spring-framework-reference/htmlsingle/#aop-introduction-defn

Under 8.1.1, item weaving, it says:

Weaving: linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime.

Spring doesn't do the same type of load-time weaving as AspectJ, but works on proxies, as described in another part of the documentation:

http://docs.spring.io/spring/docs/4.0.1.RELEASE/spring-framework-reference/htmlsingle/#aop-understanding-aop-proxies

Edit: Just saw your comment, you are correct in that assumption. The documentation gives a rather complete explanation of how it works exactly. :)

like image 40
sheltem Avatar answered Nov 10 '22 19:11

sheltem