创建名称为"projectingArgumentResolverBeanPostProcessor"的bean时出错

编程入门 行业动态 更新时间:2024-10-26 08:30:06
本文介绍了创建名称为"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为空,但是现在他们添加了此检查如果您没有至少一种方法的安全性启用元数据源后,它们将引发您正在获取的异常(在所有全局方法配置的组成中,实际上未激活任何注释支持").当我从春季5.0.7更新到5.1.5时,这发生在我身上.这是问题,其中讨论了此更改

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时出错

本文发布于:2023-10-28 17:50:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537348.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:quot   projectingArgumentResolverBeanPostProcessor   bean

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!