Antes de la primavera, presente @GetMapping
, solo hay una anotación que nos importa @RequestMapping
, por lo tanto, este aspecto funciona
@Before("within(aa.bb.*.rest..*) && execution(public * *(..)) && @within(org.springframework.web.bind.annotation.RestController) && @annotation(org.springframework.web.bind.annotation.RequestMapping)")
Pero después podemos usar @GetMapping
, @PostMapping
, este punto no funciona, pero estas anotaciones tienen una meta anotación @RequestMapping
.
¿Hay alguna forma de interceptar fácilmente todos los @RequestMapping
/ @{Get,Post,Put,Patch,..}Mapping
?
¡Encontré que esta sintaxis aquí funciona para mí!
@Pointcut("execution(@(@org.springframework.web.bind.annotation.RequestMapping *) * *(..))") public void requestMappingAnnotations() { }
También puedo enumerarlos a todos.
@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.PatchMapping)" + "|| @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) {}