如果没有Maven重建,无法在IntelliJ IDEA中运行AspectJ CTW应用程序



编辑/更新:委托IDE构建/运行操作maven在IntelliJ设置解决问题,但如何处理它没有它?

我有以下问题:

我在我的GetSthAspect类中改变了一些东西->然后我运行maven clean install(让我们假设我必须总是在我的应用程序中做clean install) ->运行spring app ->我看到错误:

java.lang.NoSuchMethodError: com.example.demo.aspects.GetSthAspect.aspectOf()Lcom/example/demo/aspects/GetSthAspect;
at com.example.demo.aspects.A.shouldDoSthAndCallMethodGetSth(A.java:15) ~[classes/:na]
at com.example.demo.aspects.AspectApp.main(AspectApp.java:18) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.10.jar:5.3.10]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.10.jar:5.3.10]
...

然后我停止app ->再次执行maven clean install ->再次运行应用程序,现在一切正常。

当我在我的GetSthAspect类中改变了一些东西,我想在app中看到我的改变时,总是这样。为什么呢?为什么我必须创建app ->运行app ->停止应用程序->再次构建应用程序,并运行它,以我的方面工作良好吗?我该怎么做才能避免这种情况呢?

GetSthAspect

@Aspect
public class GetSthAspect {
Logger logger = LoggerFactory.getLogger(GetSthAspect.class);
@Around("call(* Ent.getSth())")
public Object around(ProceedingJoinPoint  pjp) throws Throwable {
logger.info("Inside around + 12:52");
Ent ent = (Ent) pjp.getTarget();
logger.info("Number: " + ent.getImportantNumber());
return pjp.proceed();
}
}

一些类

public class AspectApp {
Logger logger = LoggerFactory.getLogger(AspectApp.class);
@GetMapping("/")
public String main() {
logger.info("Method main started + 11:01");
A a = new A();
a.shouldDoSthAndCallMethodGetSth(1);
}
}

public class A {
Logger logger = LoggerFactory.getLogger(A.class);
public void shouldDoSthAndCallMethodGetSth(Integer a) {
// ...
Ent ent = new Ent();
ent.setImportantNumber(1);
logger.info("Method A do sth and ...");
ent.getSth();
}
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Testing</name>
<description>App for tests</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.7</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<configuration>
<complianceLevel>11</complianceLevel>
<source>11</source>
<target>11</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>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

我不知道问题在哪里。通常情况下,您不需要在每次更改代码时都保持maven clean install。我建议你使用devtools也许

相关内容

  • 没有找到相关文章

最新更新