Spring Aspectj @Before all rest method

前端 未结 1 1991
猫巷女王i
猫巷女王i 2021-01-15 17:10

Before spring introduce @GetMapping, there only one annotation we care about @RequestMapping, so, this aspect works

@Before(\"withi         


        
相关标签:
1条回答
  • 2021-01-15 17:28

    I found this syntax here works for me!

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

    Also I can list them all

    @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) {}
    
    0 讨论(0)
提交回复
热议问题