我有一个Java EE Web服务(REST),现在想使用AspectJ来创建一个规则,打印出每个传入的服务调用及其参数.
我刚刚阅读了本 教程并实现了以下代码:
的pom.xml
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.10</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<complianceLevel>1.8</complianceLevel>
<source>1.8</source>
<target>1.8</target>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<Xlint>ignore</Xlint>
<encoding>UTF-8 </encoding>
</configuration>
<executions>
<execution>
<goals>
<!-- use this goal to weave all your main classes -->
<goal>compile</goal>
<!-- use this goal to weave all your test classes -->
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
...并创建了一个Test.aj文件,带有一个Pointcut,它应该在调用getSignOfLife()后打印出一个teststring:
import de.jack.businesspartner.service.BusinessPartnerServiceImpl;
public aspect TestAspectJ {
pointcut getSignOfLife() :
call(void BusinessPartnerServiceImpl.getSignOfLife());
before() : …Run Code Online (Sandbox Code Playgroud)