AspectJ配置/设置-切入点未启动



我正在尝试运行我的第一个AspectJ方面。根据我能找到的文档,安装程序对我来说还可以。例如

  • 开发者网站:https://github.com/kriegaex/org.aspectj
  • 设置说明:https://github.com/eclipse/org.aspectj/blob/master/docs/developer/IDE.md
  • 连接点示例:https://www.eclipse.org/aspectj/doc/released/progguide/language-joinPoints.html

但无论我今天尝试了什么选项,任何方面都不会开火。

我相信切入点正确地指向了我的方法调用,因为当我更改它时,我收到了关于没有使用切入点的错误。(现在没有发生这种情况-不知道我做了什么:-(((

那么设置中有问题吗?切入点?你如何处理这种情况?我是不是在文件中遗漏了什么?

POM-

<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<!--
<groupId>dev.aspectj</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.13.2-SNAPSHOT</version>
-->
<executions>
<execution>
<goals>
<goal>compile</goal>       <!-- use this goal to weave all your main classes -->
<goal>test-compile</goal>  <!-- use this goal to weave all your test classes -->
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.9.7</version>
</dependency>
</dependencies>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<forceAjcCompile>true</forceAjcCompile>
<sources/>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
<complianceLevel>11</complianceLevel>
<source>11</source>
<target>11</target>
<verbose>true</verbose>
<Xlint>warning</Xlint>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
.....
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>22.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/dev.aspectj/aspectj-maven-plugin -->
<dependency>
<groupId>dev.aspectj</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.13.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.7</version>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.7</version>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjtools -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.9.7</version>
</dependency>
</dependencies>

方面

public aspect   MdDOMAINChildAspect {
pointcut myExceptionHandlerPointcut(): execution(void mdDOMAIN.MdDOMAINInstance.testCall() );
before(): myExceptionHandlerPointcut() {
System.out.println("-------------- Aspect Advice Logic ---------------");
}

@Data
public class MdDOMAINInstance {

@MdDOMAINChildAnnotation(selectName = "Indicators")
public MdDOMAINInstance selectFilingIndicators() throws NoSuchMethodException {
testCall();
Method m=this.getClass().getMethod("selectFilingIndicators");
MdDOMAINChildAnnotation metaidAnnotation=m.getAnnotation(MdDOMAINChildAnnotation.class);
System.out.println("Annotation: " + metaidAnnotation.selectName());
return this;
}
public void testCall()
{
System.out.println("In testCall()");
return ;
}
}

测试

class MdDOMAINInstanceTest {
@Test
void selectFilingIndicatorsTest() throws NoSuchMethodException {
MdDOMAINInstance mdDOMAINInstance = new MdDOMAINInstance().selectFilingIndicators();
}
}

MAVEN测试运行

clean test -Dtest=MdDOMAINInstanceTest -f pom.xml

MAVEN测试运行结果

"C:Program FilesJavajdk-11.0.12binjava.exe" -Dmaven.multiModuleProjectDirectory=....IdeaProjectsus-MYROOT-DOMAIN-004 "-Dmaven.home=C:Program FilesJetBrainsIntelliJ IDEA 2020.1pluginsmavenlibmaven3" "-Dclassworlds.conf=C:Program FilesJetBrainsIntelliJ IDEA 2020.1pluginsmavenlibmaven3binm2.conf" "-Dmaven.ext.class.path=C:Program FilesJetBrainsIntelliJ IDEA 2020.1pluginsmavenlibmaven-event-listener.jar" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2020.1libidea_rt.jar=52349:C:Program FilesJetBrainsIntelliJ IDEA 2020.1bin" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJetBrainsIntelliJ IDEA 2020.1pluginsmavenlibmaven3bootplexus-classworlds-2.6.0.jar;C:Program FilesJetBrainsIntelliJ IDEA 2020.1pluginsmavenlibmaven3bootplexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.version=2021.3.2 clean test -Dtest=MdDOMAINInstanceTest
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for us-MYROOT:us-MYROOT-DOMAIN-004:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.version' for org.junit.jupiter:junit-jupiter:jar is either LATEST or RELEASE (both of them are being deprecated) @ line 117, column 22
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 20, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] --------------< us-MYROOT:us-MYROOT-DOMAIN-004 >--------------
[INFO] Building us-MYROOT-DOMAIN-004 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ us-MYROOT-DOMAIN-004 ---
[INFO] Deleting .....IdeaProjectsus-MYROOT-DOMAIN-004target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ us-MYROOT-DOMAIN-004 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ us-MYROOT-DOMAIN-004 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to .....IdeaProjectsus-MYROOT-DOMAIN-004targetclasses
[INFO] 
[INFO] --- aspectj-maven-plugin:1.14.0:compile (default) @ us-MYROOT-DOMAIN-004 ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ us-MYROOT-DOMAIN-004 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ us-MYROOT-DOMAIN-004 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to .....IdeaProjectsus-MYROOT-DOMAIN-004targettest-classes
[INFO] 
[INFO] --- aspectj-maven-plugin:1.14.0:test-compile (default) @ us-MYROOT-DOMAIN-004 ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[WARNING] You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl
Lombok supports: OpenJDK javac, ECJ
<unknown source file>:<no line information>
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ us-MYROOT-DOMAIN-004 ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running mdDOMAIN.MdDOMAINInstanceTest
In testCall()
Annotation: Indicators
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.065 s - in mdDOMAIN.MdDOMAINInstanceTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  22.238 s
[INFO] Finished at: 2022-10-21T20:14:46+11:00
[INFO] ------------------------------------------------------------------------
Process finished with exit code 0

为了避免这个问题,您是否尝试过不使用龙目?试着在测试类中手动执行Lombok注释的操作。

在我们确定这解决了问题之后,我们可以开始寻找可能的解决方案。如果这真的是您的第一个AspectJ问题,那么您不应该从像AspectJ+Lombok这样的困难组合开始。

此外,如果@Data类是不可变的,那么您可能根本不需要Lombok,并且可以使用最新的Java版本和本地Java记录。

最新更新