EDIT/UPDATE: Delegate IDE build/run actions to maven in IntelliJ settings solve the problem, but how to handle it without it?
I have the following problem:
I change something in my GetSthAspect class -> Then I run maven clean install (let's assume I have to always do clean install in my app) -> Run spring app -> And I see error:
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]
...
Then I stop app -> Again do maven clean install -> Again run app and now everything works fine.
It's always like that when I change something in my GetSthAspect class and I want to see my changes in app. Why is that? Why I have to build app -> run app -> stop app -> again build app and run it in order to my aspects works fine? What should I do to avoid this situation?
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();
}
}
some class
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);
}
}
A
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>
CodePudding user response:
I can't tell where the problem is. normally you don't need to keep to maven clean install everytime you change something in your code.I suggest you use devtools maybe
CodePudding user response:
Delegate IDE build/run actions to maven in IntelliJ settings solve the problem, but how to handle it without settings change?