本文介绍了Spring Aspectj @所有其余方法之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在春季介绍@GetMapping
之前,我们只关心一个注释@RequestMapping
,因此,这一方面有效
Before spring introduce @GetMapping
, there only one annotation we care about @RequestMapping
, so, this aspect works
@Before("within(aa.bb.*.rest..*) && execution(public * *(..)) && @within(org.springframework.web.bind.annotation.RestController) && @annotation(org.springframework.web.bind.annotation.RequestMapping)")
但是在我们可以使用@GetMapping
,@PostMapping
之后,这一点不起作用,但是这些注释具有元注释@RequestMapping
.
But after we can use @GetMapping
, @PostMapping
, this point not works, but these annotations have a meta annotation @RequestMapping
.
有什么办法可以轻松拦截所有@RequestMapping
/@{Get,Post,Put,Patch,..}Mapping
吗?
Is there any way to easily intercept all @RequestMapping
/@{Get,Post,Put,Patch,..}Mapping
?
推荐答案
我在此处为我找到了这种语法!
I found this syntax here works for me!
@Pointcut("execution(@(@org.springframework.web.bind.annotation.RequestMapping *) * *(..))")
public void requestMappingAnnotations() { }
我也可以全部列出
@Pointcut("within(aa.bb.*.rest..*) && @within(org.springframework.web.bind.annotation.RestController)")
public void restControllers() {}
@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping) " +
"|| @annotation(org.springframework.web.bind.annotation.GetMapping)" +
"|| @annotation(org.springframework.web.bind.annotation.PostMapping)" +
"|| @annotation(org.springframework.web.bind.annotation.PathVariable)" +
"|| @annotation(org.springframework.web.bind.annotation.PutMapping)" +
"|| @annotation(org.springframework.web.bind.annotation.DeleteMapping)"
)
public void mappingAnnotations() {}
@Pointcut("execution(@(@org.springframework.web.bind.annotation.RequestMapping *) * *(..))")
public void requestMappingAnnotations() { }
@Before("restControllers() && requestMappingAnnotations()")
public void onExecute(JoinPoint jp) {}
这篇关于Spring Aspectj @所有其余方法之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!