在 Web 服务中添加 AspectJ
2022-09-04 21:21:42
我有一个Java EE Webservice(REST),现在想使用AspectJ来创建一个规则,该规则将打印出每个传入的服务调用及其参数。
我刚刚阅读了本教程并实现了以下代码:
聚甲醛.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>
...并创建了一个 Test.aj 文件,其中包含一个 Pointcut,该文件应在调用 getSignOfLife() 后打印出测试字符串:
import de.jack.businesspartner.service.BusinessPartnerServiceImpl;
public aspect TestAspectJ {
pointcut getSignOfLife() :
call(void BusinessPartnerServiceImpl.getSignOfLife());
before() : getSignOfLife() {
System.err.println("ADKL TEST ASPECT");
}
}
--> 但是如果我调用getSignOfLife()方法,则不会发生任何事情。你可以帮我吗?