我在单独的Maven项目中创建了aspectJ
类:
@Aspect
public class AspectE {
@Pointcut("execution(@EntryPoint * *.*(..))")
public void defineEntryPoint() {
}
@Before("defineEntryPoint()")
public void setThreadName(JoinPoint joinPoint) {
...
}
@After("defineEntryPoint()")
public void removeThreadName(JoinPoint joinPoint) {
...
}
}
然后在第二个项目中,我注释了几个方法并添加到pom.xml
:
<dependency>
<groupId>first-project</groupId>
<artifactId>first-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.0</version>
</dependency>
但仍然没有看到。我错过了一些步骤吗?我该怎么办?
答案 0 :(得分:3)
答案 1 :(得分:2)
为了使用您的库正确编写代码,您应该在依赖关系中并在aspectj weaver中声明它们:
<dependencies>
<!-- Aspectj lib -->
<dependency>
<groupId>com.my.group</groupId>
<artifactId>my-aspect-lib</artifactId>
<version>1.0</version>
</dependency>
<!-- Other dependencies -->
</dependencies>
<build>
<!-- Specific build configuration -->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>com.my.group</groupId>
<artifactId>my-aspect-lib</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
</plugin>
<!-- Other plugins configuration -->
</plugins>
</build>
<!-- Other settings -->
答案 2 :(得分:1)
你必须用代码编织方面。这可以通过两种方式完成:
加载时间编织更加通用,但设置正确可能有点困难。它在启动期间(编织发生时)消耗更多的CPU,并且还具有内存占用。 编译时编织显然会在编译过程中消耗更多的CPU,但是每次重启都不会付出代价。
答案 3 :(得分:0)
我遇到了同样的问题...但是在我添加了这个maven repo之后它正在工作
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>