Spring AspectJ caching versus AspectJ-mode transactions

My question is about Spring AspectJ mode and especially its inclusion for:

  • Transaction management
  • Caching

1) I noticed that to enable AspectJ mode for transaction management I needed to do the following:

@Configuration @EnableTransactionManagement(mode = AdviceMode.ASPECTJ) 

2) While to use AspectJ mode for caching, it seems you need:

-Put the following phrase into the Tomcat lib java directory: org.springframework:spring-instrument-tomcat -Add the following line to Tomcat server.xml:

 <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/> 

- add the following configuration:

 @Configuration @EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.ENABLED) public class LoadTimeWeavingConfiguration implements LoadTimeWeavingConfigurer { @Override public LoadTimeWeaver getLoadTimeWeaver() { return new ReflectiveLoadTimeWeaver(); } } 

- finally, you can use AspectJ mode as follows:

 @Configuration @EnableCaching(mode = AdviceMode.ASPECTJ) 

Is it correct? If so, why is AspectJ-mode caching different from AspectJ transaction support?

+6
source share
1 answer

The additional configuration you specified for the @EnableCaching case is no longer needed than the @EnableTransactionManagement case. If you select mode = AdviceMode.ASPECTJ , it means that it will use AspectJ instead of the CGLIB proxy to manage transactions / cache. If during compilation with support for spring-aspects-<version>.jar specified as an aspect library, it should work out of the box (given that in the application context all other beans necessary for transaction management / cache cache settings are available). If you do not use weaving at compile time, but instead want to switch to the boot time layer, the presence of -javaagent:/path/to/aspectjweaver-<version>.jar on the command line as a JVM argument is sufficient. ReflectiveLoadTimeWeaver and TomcatInstrumentableClassLoader are only required if your assembly does not use weaving at compile time, and there is no loading time triangulation in the virtual machine, and you still want the loading time to be done by loading classes.

+1
source

Source: https://habr.com/ru/post/970904/


All Articles