春天的AOP执行不能用于多个参数

问题描述 投票:0回答:1

我想在我的方面方法中记录每个请求映射,并使用 @Before("execution(@(@org.springframework.web.bind.annotation.RequestMapping *) * *(..))")

这个执行公式只适用于有1个参数的pathvariable方法(所以哪个是 /people/{id}).

对于多变量的在本例中为例 getAllPeople method 这个方面方法没有被触发。如何使每一个有1个参数或更多参数的请求都有一个fire aspect方法?先谢谢你。

我的应用程序配置 。

@Configuration
@EnableAspectJAutoProxy
public class AppConfig {

}

我的控制器。

@RestController
public class MainController {

    @GetMapping("/people") 
    private ResponseEntity<People> getAllPeople(@RequestParam(name = "page", required = false) Integer page,
            @RequestParam(name = "size", required = false) Integer size,
            @RequestParam(name = "sortBy", required = false) Boolean sortByNameOrEpCount)

    System.out.println("getall works");

} 

@GetMapping("/people/{id}") 
    private ResponseEntity<People> getPeople(@PathVariable(name = "id") int id)

    System.out.println("getpeople works");
ResponseEntity.notFound().build();
} 

我的 aspect 文件。

@Aspect
@Component
public class AppAspect {

    @Before("execution(@(@org.springframework.web.bind.annotation.RequestMapping *) * *(..))")
    public void loggingEndPointRequests(JoinPoint joinPoint) {

        System.out.println("loggingEndPointRequests" + joinPoint.getSignature().getName());
    }

}
java spring aop spring-aop
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.