I have some issue in Logging all the methods when a service calls. Code is like this:
package com.myproject.controller;
@RestController(/person)
public class Controller{
public Person getpersonInfo(){
......
getValidPerson();
}
}
public Person getValidPerson() {
isPersonValid(Person person);
....
}
Person class Methods :
package com.myproject.dao;
public class Dao{
public boolean isPersonValid(){
//Checks for the person is Valid
}
}
Aspect Class :
package com.myproject;
@Component
@Aspect
public class Logging{
@Before("execution(* com.myproject..*.*(..)))")
public void beforeServiceCall(Jointpoint jp) {
//Some Logging function
}
}
Main class like this
package com.myproject;
@SpringBootApplication
@EnableAutoConfiguration
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
@EnableAspectJAutoProxy()
public class Main implements LoadTimeWeavingConfigurer{
public static void main(String[] args){
......
}
}
Pom file :
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-instrument -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.1</version>
</dependency>
When I call the service http://localhost:8080/person - GET getpersonInfo() is only Logged in this case, I have also tried LTW , but do not solve
I need to log all internal methods to the service like is getValidPerson(),isPersonValid() mentioning all arguments to those invoked method.
The classical case, answered here about 378 times before:
this.someMethod()
(equivalent to justsomeMethod()
) becausethis
is the real object, not the proxy. No proxy usage means no Spring AOP interception. This is well-documented. Look for the term "self-invocation" in the Spring AOP manual.Some remarks:
aspectjweaver
dependency from 1.8.1 to 1.8.10 which contains lots of bugfixes and small improvements with regard to Java 8.aspectjrt
because it is a subset ofaspectjweaver
. The former is useful for compile-time weaving, not for load-time weaving.