背景
spring boot webmvc项目重构为webflux项目,原PreAuthorize注解报错。
代码和报错信息
@PreAuthorize
会发生如下错误。1
2
3
4
5
6
7
8
9@RestController
@RequestMapping("sample")
public class SampleController {
@RequestMapping
@PreAuthorize("hasAuthority('ADMIN_ROLE')")
public Mono index(@AuthenticationPrincipal UserDetails useDetails) {
return Mono.empty();
}
}
错误如下
1 | No MethodInvocation found: Check that an AOP invocation is in progress, and that the ExposeInvocationInterceptor is upfront in the interceptor chain. Specifically, note that advices with order HIGHEST_PRECEDENCE will execute before ExposeInvocationInterceptor! |
解决方案
@EnableReactiveMethodSecurity
如果下面可以处理的顺序是最高级别,则它起作用
1 | (order = Ordered.HIGHEST_PRECEDENCE) |