2017-03-07 4 views
1

Vor Frühjahr @GetMapping einführen, gibt es nur eine Anmerkung wir kümmern uns um @RequestMapping, so ist dieser Aspekt arbeitetFrühling aspectj @Before alle übrigen Verfahren

@Before("within(aa.bb.*.rest..*) && execution(public * *(..)) && @within(org.springframework.web.bind.annotation.RestController) && @annotation(org.springframework.web.bind.annotation.RequestMapping)") 

Aber nachdem wir @GetMapping verwenden können, @PostMapping, dieser Punkt nicht funktioniert, aber diese Annotationen haben eine Meta-Annotation @RequestMapping.

Gibt es eine Möglichkeit, alle @RequestMapping/@{Get,Post,Put,Patch,..}Mapping einfach abzufangen?

Antwort

2

Ich fand diese Syntax here funktioniert für mich!

@Pointcut("execution(@(@org.springframework.web.bind.annotation.RequestMapping *) * *(..))") 
public void requestMappingAnnotations() { } 

Auch kann ich sie alle aufzählen

@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) {} 
Verwandte Themen