Error creating bean with name 'projectingArgumentResolverBeanPostProcessor' defi

984 阅读1分钟

学Spring Security的时候报了个错 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectingArgumentResolverBeanPostProcessor' defined in class path resource [org/springframework/data/web/config/ProjectingArgumentResolverRegistrar.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metaDataSourceAdvisor': Cannot resolve reference to bean 'methodSecurityMetadataSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityMetadataSource' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.access.method.MethodSecurityMetadataSource]: Factory method 'methodSecurityMetadataSource' threw exception; nested exception is java.lang.IllegalStateException: In the composition of all global method configuration, no annotation support was actually activated 百度了一下我在 SecurityConfig上加了这个注释

@EnableGlobalMethodSecurity

忘记在后面方法加上

prePostEnabled=true

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

其中注解@EnableGlobalMethodSecurity有几个方法:

  • prePostEnabled 确定 前置注解[@PreAuthorize,@PostAuthorize,..] 是否启用
  • securedEnabled 确定安全注解 [@Secured] 是否启用
  • jsr250Enabled 确定 JSR-250注解 [@RolesAllowed..]是否启用

启用 prePostEnabled 后可使用,@PreAuthorize@PostAuthorize@PreFilter@PostFilter