控制器上的方面方法拦截



我有一个Spring mvc控制器,带有to方法:

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

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

我想用一个方面拦截这些方法:

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

此方面在method1中工作正常,在method2中失败。我做错了什么?

具有@RequestMapping注释的特定包中方法的切入点表达式:

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

最新更新