使用AspectJ on annoted方法的Spring导致404错误

时间:2017-07-17 18:30:28

标签: java spring annotations aspectj spring-aop

我有以下方面使用所有REST控制器:

@Pointcut(value="execution(* com.company.app.features.*.controller.*.*(..))")
public void controller() { }

@Before("controller()")
public void before(JoinPoint jp) {
    // Log
}

根据需要,@Pointcut中定义的包中的所有方法都可以正常工作。

但是,当我尝试将@Before指向仅使用@GetMapping(..)注释的方法时,该网址会产生404错误,但是另一个通常会起作用。

我做错了什么?没有人尝试过:

  • 仅修改@Before:@Before("method() && @annotation(GetMapping)")
  • 仅修改@Pointcut:@Pointcut(value="execution(@GetMapping com.company...
  • 仅修改@Pointcut:@Pointcut(value="execution(@GetMapping * com.company...

相同的结果(错误404)是当我在控制器类上实现接口时,@Override使用@GetMapping注释的方法,并将此方法从接口放到@Pointcut as第一段代码说。我建议背后有类似的事情。有人会解释我吗?

1 个答案:

答案 0 :(得分:1)

@Pointcut(value="execution(* com.company.app.features.*.controller.*.*(..))")
public void controller() { }

@Pointcut(value="execution(@within(org.springframework......GetMapping)")
public void getMapping() { }


@Before("controller() && getMapping(object)")
public void controllerGetMapping(Object objectIfYouNeedIt) {
    // Log
}
相关问题