2017-03-07 10 views
1

@GetMapping紹介するすべての残りの方法、私たちは気に一つだけのアノテーションを約@RequestMappingので、この点があっ春AspectJの@Before春前

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

に動作します。しかし、我々は@GetMapping@PostMapping、この時点ではない作品を使用することができた後、これらの注釈にはメタ注釈@RequestMappingがあります。

すべてを簡単に傍受する方法はありますか@RequestMapping/@{Get,Post,Put,Patch,..}Mapping

答えて

2

この構文が見つかりましたhereは私のために働きます!

@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) {} 
を一覧表示することができます