Umar Umar - 1 year ago 119
Java Question

Aspect not getting executed

My AspectConfig

public class LoggingAspectConfig {

public SampleRestService restService() {
return new SampleRestService();

public ServiceMonitor serviceMonitor() {
return new ServiceMonitor();

My Aspect

public class ServiceMonitor {

public void requestMapping() {}

public void logServiceStart(JoinPoint joinPoint) {
System.out.println("Start: " + joinPoint);


My Sample Service

public class SampleRestService {

public static void getParams(){
String url = "<sample url>";

HttpHeaders headers = new HttpHeaders();

HttpEntity entity = new HttpEntity(headers);

RestTemplate restTemplate = new RestTemplate();

ResponseEntity<String> response2 = url, HttpMethod.GET, entity , String.class );



My Annotation

public @interface Monitor {


I am calling with this getParams from a Controller which is annotated with @Component

Please let me know if i am missing something,

Do i need to add some more config? or is the pointcut expression wrong.

I have the following jars included


Answer Source

You're using Spring AOP instead of AspectJ, as indicated by the configuration annotation @EnableAspectJAutoProxy. Spring AOP is not equivalent to AspectJ weaving. Spring AOP works by proxying your spring managed beans, hence it only works on spring beans, with all the limitations of proxy based AOP vs byte-code weaving. Your candidate method getParams is a static method, hence it's not a candidate for Spring AOP. Use either normal AspectJ (compile time weaving or load-time weaving) or remove the static keyword from the method if you intend to stick with Spring AOP. See this answer for further reference.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download