【问题标题】:Error creating bean with name 'projectingArgumentResolverBeanPostProcessor'创建名为“projectingArgumentResolverBeanPostProcessor”的 bean 时出错
【发布时间】:2019-08-28 04:27:04
【问题描述】:

我在我的项目中设置我的网络安全,但我看到一个错误。 这是错误

org.springframework.beans.factory.BeanCreationException: 错误 创建名为“projectingArgumentResolverBeanPostProcessor”的bean 在类路径资源中定义 [org/springframework/data/web/config/ProjectingArgumentResolverRegistrar.class]: bean 实例化之前的 BeanPostProcessor 失败;嵌套的 例外是 org.springframework.beans.factory.BeanCreationException: 创建名为“metaDataSourceAdvisor”的 bean 时出错:无法解析 设置时引用 bean 'methodSecurityMetadataSource' 构造函数参数;嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 创建名称为“methodSecurityMetadataSource”的bean 类路径资源 [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: 通过工厂方法实例化 Bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.security.access.method.MethodSecurityMetadataSource]: 工厂方法“methodSecurityMetadataSource”抛出异常;嵌套的 异常是java.lang.IllegalStateException: 在组成 所有全局方法配置,实际上没有注释支持 激活于 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] 在 org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:240) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:721) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:534) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] 在 com.supermarket.SupermarketApplication.main(SupermarketApplication.java:19) [类/:na]

我的鳕鱼是:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
    @Autowired
    private Environment env;
    @Autowired
    private UserSecurityService usersecurityservice;
    private BCryptPasswordEncoder passwordencoder(){
        return SecurityUtility.passwordEncoder();
    }
    private static final String[]PUBLIC_MATCHES = {
            "/css/**",
            "/js/**",
            "/img/**",
            "/signUp",
            "/",
            "/newUser",
            "/forgetPassword",
            "/login",
            "/fonts/**",
            "/bookshelf/**",
            "/bookDetail/**",
            "/hours",
            "/faq",
            "/searchByCategory",
            "/searchBook"

    };
@Override
protected void configure(HttpSecurity   http)throws Exception{
    http
    .authorizeRequests().
    /*antMatchers("/**").*/
    antMatchers(PUBLIC_MATCHES).
    permitAll().anyRequest().authenticated();

http
    .csrf().disable().cors().disable()
    .formLogin().failureUrl("/login?error")
    .defaultSuccessUrl("/")
    .successForwardUrl("/login")
    .and()
    .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
    .logoutSuccessUrl("/?logout").deleteCookies("remember-me").permitAll()
    .and()
    .rememberMe();

}
@Autowired
public void configureGlobal (AuthenticationManagerBuilder auth) throws Exception{
    auth.userDetailsService(usersecurityservice).passwordEncoder(passwordencoder());
}

} userSecurity 类是:

@Service
public class UserSecurityService implements UserDetailsService {

    @Autowired()
    private UserRepository userRepository;

public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    // TODO Auto-generated method stub
    try{

    }catch(Exception ex){
        System.out.println("Error acoured hear:");
    }
    User user=userRepository.findByUsername(username);
    if(null==user){
        throw new UsernameNotFoundException("Username not found");
    }
    return user;
}

当我删除 '@EnableGlobalMethodSecurity' 注释程序运行正确 我以前用过这个鳕鱼,它工作正常。

【问题讨论】:

    标签: java spring spring-boot websecurity


    【解决方案1】:

    你最近更新 spring 了吗?在以前的版本中,可以使用 null MethodSecurityMetadataSource,但现在他们添加了 this check,如果您没有启用至少一个方法安全元数据源,它们会抛出您得到的异常(“在组合在所有全局方法配置中,实际上没有激活注释支持”)。当我从 spring 5.0.7 更新到 5.1.5 时,这发生在我身上。这是 the issue 讨论此更改的地方

    要修复它,请在 @EnableGlobalMethodSecurity 注释属性中启用元数据源之一,或者,如果您像我一样使用某种 GlobalMethodSecurityConfiguration,请确保方法 customMethodSecurityMetadataSource 返回非空

    【讨论】:

    • 解决方法!
    【解决方案2】:

    您遇到此问题是因为您没有正确注释。你应该像这样添加它:@EnableGlobalMethodSecurity(prePostEnabled = true)

    【讨论】:

    • 这行得通,但你能分享一下为什么行得通吗?
    猜你喜欢
    • 2019-09-17
    • 2021-11-28
    • 2020-10-03
    • 2015-03-18
    • 2021-03-17
    • 2021-06-18
    • 2019-07-21
    • 2016-04-04
    • 2019-11-15
    相关资源
    最近更新 更多