異常內容:
Caused by: java.lang.IllegalStateException: In the composition of all global method configuration, no annotation support was actually activated at org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration.methodSecurityMetadataSource(GlobalMethodSecurityConfiguration.java:373) ~[spring-security-config-5.3.3.RELEASE.jar:5.3.3.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_242] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_242] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_242] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_242] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
導致的原因是
@EnableGlobalMethodSecurity注解 prePostEnabled 屬性,是否開啟 PreAuthory 注解功能,類似的還有其他注解,Secured注解等等,這些注解的默認值都是false,也就是不啟用
解決方法就是配置以下就可以了:
@EnableGlobalMethodSecurity(prePostEnabled = true)