AspectJ 插件 Aspect Config 与 Maven 使用外部 Jar for Aspect
我正在使用 Perf4j 进行性能日志记录。
它指定您使用 aop.xml 来定义要在编译时调用哪个方面,具体取决于您使用的日志系统。我无法让它获取 src/main/webapp/meta-inf/aop.xml 中的 aop.xml 文件
我不知道如何让我的 Maven 插件只编织 log4j 方面。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<outxml>true</outxml>
<source>1.6</source>
<target>1.6</target>
<weaveDependencies>
<dependency>
<groupId>org.perf4j</groupId>
<artifactId>perf4j</artifactId>
</dependency>
</weaveDependencies>
<aspects>
<includes>
<include>org.perf4j.log4j.aop.TimingAspect</include>
</includes>
</aspects>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
当我打包时,我得到以下内容。
[INFO] --- aspectj-maven-plugin:1.3:compile (default) @ trace-web ---
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceJSONController.getResults(javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpServletRequest))' in Type 'com.idna.trace.web.controllers.TraceJSONController' (TraceJSONController.java:121) advised by around advice from 'org.perf4j.commonslog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceJSONController.getResults(javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpServletRequest))' in Type 'com.idna.trace.web.controllers.TraceJSONController' (TraceJSONController.java:121) advised by around advice from 'org.perf4j.log4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceJSONController.getResults(javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpServletRequest))' in Type 'com.idna.trace.web.controllers.TraceJSONController' (TraceJSONController.java:121) advised by around advice from 'org.perf4j.javalog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceJSONController.getResults(javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpServletRequest))' in Type 'com.idna.trace.web.controllers.TraceJSONController' (TraceJSONController.java:121) advised by around advice from 'org.perf4j.slf4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:106) advised by around advice from 'org.perf4j.commonslog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:106) advised by around advice from 'org.perf4j.log4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:106) advised by around advice from 'org.perf4j.javalog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:106) advised by around advice from 'org.perf4j.slf4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsAddressModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:282) advised by around advice from 'org.perf4j.commonslog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsAddressModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:282) advised by around advice from 'org.perf4j.log4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsAddressModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:282) advised by around advice from 'org.perf4j.javalog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsAddressModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:282) advised by around advice from 'org.perf4j.slf4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsBmdModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:419) advised by around advice from 'org.perf4j.commonslog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsBmdModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:419) advised by around advice from 'org.perf4j.log4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsBmdModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:419) advised by around advice from 'org.perf4j.javalog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsBmdModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:419) advised by around advice from 'org.perf4j.slf4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO]
答案是Perf4J必须指定log4jonly,并且据我所知,它不能在maven插件配置中完成。
<dependency>
<groupId>org.perf4j</groupId>
<artifactId>perf4j</artifactId>
<version>0.9.13</version>
<classifier>log4jonly</classifier>
</dependency>
I am using Perf4j to do performance logging.
It specifies that you use aop.xml to define which Aspect you want to be called at compile time depending on which logging system you are using. I cannot get it to pick up the aop.xml file which is in src/main/webapp/meta-inf/aop.xml
I cannot figure out how to get my Maven plugin to only weave the log4j aspect.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<outxml>true</outxml>
<source>1.6</source>
<target>1.6</target>
<weaveDependencies>
<dependency>
<groupId>org.perf4j</groupId>
<artifactId>perf4j</artifactId>
</dependency>
</weaveDependencies>
<aspects>
<includes>
<include>org.perf4j.log4j.aop.TimingAspect</include>
</includes>
</aspects>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
When I package I get the following.
[INFO] --- aspectj-maven-plugin:1.3:compile (default) @ trace-web ---
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceJSONController.getResults(javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpServletRequest))' in Type 'com.idna.trace.web.controllers.TraceJSONController' (TraceJSONController.java:121) advised by around advice from 'org.perf4j.commonslog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceJSONController.getResults(javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpServletRequest))' in Type 'com.idna.trace.web.controllers.TraceJSONController' (TraceJSONController.java:121) advised by around advice from 'org.perf4j.log4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceJSONController.getResults(javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpServletRequest))' in Type 'com.idna.trace.web.controllers.TraceJSONController' (TraceJSONController.java:121) advised by around advice from 'org.perf4j.javalog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceJSONController.getResults(javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpServletRequest))' in Type 'com.idna.trace.web.controllers.TraceJSONController' (TraceJSONController.java:121) advised by around advice from 'org.perf4j.slf4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:106) advised by around advice from 'org.perf4j.commonslog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:106) advised by around advice from 'org.perf4j.log4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:106) advised by around advice from 'org.perf4j.javalog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:106) advised by around advice from 'org.perf4j.slf4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsAddressModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:282) advised by around advice from 'org.perf4j.commonslog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsAddressModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:282) advised by around advice from 'org.perf4j.log4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsAddressModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:282) advised by around advice from 'org.perf4j.javalog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsAddressModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:282) advised by around advice from 'org.perf4j.slf4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsBmdModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:419) advised by around advice from 'org.perf4j.commonslog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsBmdModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:419) advised by around advice from 'org.perf4j.log4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsBmdModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:419) advised by around advice from 'org.perf4j.javalog.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO] Join point 'method-execution(org.springframework.web.servlet.ModelAndView com.idna.trace.web.controllers.TraceHTMLController.getDetailsBmdModelAndView(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.springframework.ui.Model))' in Type 'com.idna.trace.web.controllers.TraceHTMLController' (TraceHTMLController.java:419) advised by around advice from 'org.perf4j.slf4j.aop.TimingAspect' (perf4j-0.9.13.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))
[INFO]
The answer is that Perf4J must specify log4jonly and it cannot be done in the maven plugin configuration as far as I could see.
<dependency>
<groupId>org.perf4j</groupId>
<artifactId>perf4j</artifactId>
<version>0.9.13</version>
<classifier>log4jonly</classifier>
</dependency>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是Perf4J必须指定log4jonly,并且据我所知,它不能在maven插件配置中完成。
The answer is that Perf4J must specify log4jonly and it cannot be done in the maven plugin configuration as far as I could see.