创建名称为"projectingArgumentResolverBeanPostProcessor"的bean时出错 [英] Error creating bean with name 'projectingArgumentResolverBeanPostProcessor'

查看:1712
本文介绍了创建名称为"projectingArgumentResolverBeanPostProcessor"的bean时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Im setting my web security in my project , but i see an error. this is the error

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) [classes/:na]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectingArgumentResolverBeanPostProcessor' defined in class path resource [org/springframework/data/web/config/ProjectingArgumentResolverRegistrar.class]: BeanPostProcessor before instantiation 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 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:240) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:721) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:534) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at com.supermarket.SupermarketApplication.main(SupermarketApplication.java:19) [classes/: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类为:

} userSecurity class is:

@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"注释程序时,它会正确运行 我以前用过这种鳕鱼,它能正常工作.

When i delete '@EnableGlobalMethodSecurity' annotation program run correctly I had used this cod before and it worked correctly.

推荐答案

您最近更新了Spring吗?在以前的版本中,可以使用MethodSecurityMetadataSource为空,但是现在他们添加了问题,其中讨论了此更改

Did you update spring recently? In previous versions it was ok to have a null MethodSecurityMetadataSource, but now they added this check where if you don't have at least one method security metadata source enabled, they throw the exception that you are getting ("In the composition of all global method configuration, no annotation support was actually activated"). This happened to me when I updated from spring 5.0.7 to 5.1.5. Here is the issue where this change was discussed

要解决此问题,请在@EnableGlobalMethodSecurity批注属性中启用一个元数据源,或者,如果像我一样,您正在使用某种GlobalMethodSecurityConfiguration,请确保方法customMethodSecurityMetadataSource返回not-null

To fix it, either enable one of the metadata sources in the @EnableGlobalMethodSecurity annotation properties, or, if like me, you are using some kind of GlobalMethodSecurityConfiguration, make sure the method customMethodSecurityMetadataSource returns not-null

这篇关于创建名称为"projectingArgumentResolverBeanPostProcessor"的bean时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆