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>
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).
Weaving principles stay the same though - documentation
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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With