I'm new in using spring boot
I'm currently working on a project that requires me to log the execution of a method (elapsed time and result) using aop.
I can use spring-aop just fine, the problems comes when the aop cannot capture the internal method call (private
method) and the method call from new
object.
After browsing through many references, it looks like I should use compile-time weaving (since I have the source code with me)
my pom.xml looks like this
<dependencies>
...
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</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>
<encoding>UTF-8</encoding>
<Xlint>ignore</Xlint>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
When I run mvn clean package
, it shows the advice for the private
method and the method from new
object was being weaved, and the project was compiled successfully.
But when I start the .jar file and execute the API using Postman, it shows exception error that not occured before I was adding this compile-time weaving such as:
feign.codec.DecodeException: Type definition error: [simple type, class someClass]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException
nested exception is java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all!
How do I achieve this compile-time weaving without causing unnecessary exception when I run the program? because it was just fine when I remove the build plugin for compile-time weaving
Any response would be appreciated
P.S:
I have tried using spring-aop with self-injection using @Autowired
but it causing NPE when the internal method trying to execute .saveAll()
from @Autowired
repository and I don't know how to fix that so I choose this compile-time weaving