Plebios
Plebios

Reputation: 835

Aspect method interception over a Controller

I have a Spring mvc controller with to methods:

@RequestMapping(value = "/method1", method = GET) 
public A method1() throws Exception 
{           
    return new A();
}

and

@RequestMapping(value = "/method2", method = GET) 
public int method2() throws Exception 
{           
    return -1;
}

I want to intercept these methods with an Aspect:

@Before("execution(** com.test.controller.*(..))")
public void startLog()
{
    System.out.println("START");
}

This aspect works ok with method1 and fails with method2. What I am doing wrong?

Upvotes: 0

Views: 871

Answers (1)

akki
akki

Reputation: 451

pointcut expression for methods in a particular package having @RequestMapping annotation:

@Before("execution(* com.test.controller.*.*(..)) && @annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public void startLog()
    {
        System.out.println("START");
    }

Upvotes: 2

Related Questions