My question relates to Spring's AspectJ mode and especially how to enable it for:
- Transaction management
- Caching
1) I noticed that in order to enable the AspectJ mode for transaction management, I only had to do the following:
@Configuration
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
2) Whereas in order to use AspectJ mode for caching it seems one has to:
-Put the following jar into Tomcat's lib directory: org.springframework:spring-instrument-tomcat
-Add the following line in Tomcat's 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();
}
}
-to finally be able to use the AspectJ mode as follows:
@Configuration
@EnableCaching(mode = AdviceMode.ASPECTJ)
Is the above right? If so why is AspectJ-mode caching different from AspectJ-mode transaction support?