我的问题与 Spring 的 AspectJ 模式有关,尤其是如何启用它:
- 事务管理
- 缓存
1) 我注意到为了启用 AspectJ 模式进行事务管理,我只需要执行以下操作:
@Configuration
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
2) 而为了使用 AspectJ 模式进行缓存,似乎必须:
- 将以下 jar 放入 Tomcat 的 lib 目录: -org.springframework:spring-instrument-tomcat
在 Tomcat 的 server.xml 中添加以下行:
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
- 添加以下配置:
@Configuration
@EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.ENABLED)
public class LoadTimeWeavingConfiguration implements LoadTimeWeavingConfigurer {
@Override
public LoadTimeWeaver getLoadTimeWeaver() {
return new ReflectiveLoadTimeWeaver();
}
}
- 最终能够使用 AspectJ 模式,如下所示:
@Configuration
@EnableCaching(mode = AdviceMode.ASPECTJ)
以上是对的吗?如果是这样,为什么 AspectJ 模式缓存与 AspectJ 模式事务支持不同?