控制器

时间:2015-12-15 10:28:34

标签: java spring spring-mvc spring-aop aspect

我有一个带有方法的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。我做错了什么?

1 个答案:

答案 0 :(得分:2)

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

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