我想在我的方面方法中记录每个请求映射,并使用 @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());
}
}