我已经为tomcat(apache-tomcat-9.0.1)上运行的spring boot(1.5.6.RELEASE)应用程序设置了带有aspectj(1.8.10)注释的spring-AOP日志记录。我可以看到aop日志记录通过我的方面为我的公共方法工作,但不适用于私有方法。
来自Spring-docs-(https://docs.spring.io/spring/docs/4.3.14.RELEASE/spring-framework-reference/html/aop.html#aop-aj-ltw),
我从下面看到( LTW - 加载时间编织)是为私有/受保护方法编织方面的方法。但是在完成之后,我的方面是不记录我的spring-component的公共方法的日志。因此,根据以下帖子,我添加了更多注释 - 提到了应用程序上下文的ltw链接方面。但仍然没有这样截取或记录组件的方面
how to setup load-time weaving with Spring and Tomcat WITHOUT using the -javaagent on the command line
所以,我有以下设置:aop.xml,aspect,bean启用ltw,以及我的spring-boot启动类。 有人可以解释,还有什么设置缺失,因为我的bean启动了方面,而且通过ltw我的app-bean发生了aop-logging?
<aspectj>
<weaver options="-verbose -showWeaveInfo -debug">
<include within="com.a.b.ad.ADService"/>
</weaver>
<aspects>
<aspect name="com.a.b.ad.LoggingAspect"/>
</aspects>
</aspectj>
@Aspect
public class LoggingAspect{
@Before("execution(* com.a.b.ad.ADService.*(..))")
public void logBefore(JoinPoint joinPoint) {
logger.info("AOP call : " + joinPoint.getSignature().getName());
}
@Configuration
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.AUTODETECT)
public class AOPConfig implements LoadTimeWeavingConfigurer {
final static Logger logger = LoggerFactory.getLogger(AOPConfig.class);
@Override
public LoadTimeWeaver getLoadTimeWeaver() {
logger.info("getLoadTimeWeaver got called!");
return new ReflectiveLoadTimeWeaver();
}
}
@SpringBootApplication
@EnableAspectJAutoProxy
@EnableSpringConfigured
public class ADApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
System.out.println("Testing SpringApplicationBuilder - in "+
Thread.currentThread().getStackTrace()[1].getMethodName());
return application.sources(ADApplication.class);
}
public static void main(String[] args) {
System.out.println("Testing SpringApplicationBuilder - in "+
Thread.currentThread().getStackTrace()[1].getMethodName());
SpringApplication.run(ADApplication.class, args);
}
}
但是ltw确实被启动了(以下)并且我的方面似乎是从aop.xml读取的,而且我也看到了下面的日志,它说,它的“非编织”我的app-classes外面我的应用程序中的软件包也是如此。
19-Apr-2018 17:40:41.346 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.addTransformer Added class file transformer [org.springframework.context.weaving.AspectJWeavingEnabler$AspectJClassBypassingClassFileTransformer@cbcc71] to web application [ad].
[ParallelWebappClassLoader@9992c4] info AspectJ Weaver Version 1.8.10 built on Monday Dec 12, 2016 at 19:07:48 GMT
[ParallelWebappClassLoader@9992c4] info register classloader org.apache.catalina.loader.ParallelWebappClassLoader@9992c4
[ParallelWebappClassLoader@9992c4] info using configuration /C:/Users/A051104/Software/apache-tomcat-9.0.1/apache-tomcat-9.0.1/webapps/ad/WEB-INF/classes/META-INF/aop.xml
[ParallelWebappClassLoader@9992c4] info using configuration file:/C:/Users/A051104/Software/apache-tomcat-9.0.1/apache-tomcat-9.0.1/webapps/ad/WEB-INF/lib/spring-aspects-3.2.0.RELEASE.jar!/META-INF/aop.xml
[ParallelWebappClassLoader@9992c4] info register aspect com.a.b.ad.LoggingAspect
[ParallelWebappClassLoader@9992c4] info register aspect org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect
[ParallelWebappClassLoader@9992c4] info register aspect org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect
[ParallelWebappClassLoader@9992c4] info register aspect org.springframework.transaction.aspectj.AnnotationTransactionAspect
[ParallelWebappClassLoader@9992c4] error can't determine superclass of missing type org.springframework.transaction.interceptor.TransactionAspectSupport
[Xlint:cantFindType]
[ParallelWebappClassLoader@9992c4] debug not weaving 'com.a.b.ad.Response'
[ParallelWebappClassLoader@9992c4] debug not weaving 'com.a.restutil.RestTemplateUtil'
[ParallelWebappClassLoader@9992c4] debug not weaving 'com.a.b.ad.JiraFieldBuilder'