我有一个带有方法的Spring mvc控制器:
@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
。我做错了什么?
答案 0 :(得分:2)
具有@RequestMapping注释的特定包中的方法的切入点表达式:
@Before("execution(* com.test.controller.*.*(..)) && @annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void startLog()
{
System.out.println("START");
}