创建名称为 'projectingArgumentResolverBeanPostProcessor' 的 bean 时出错
Error creating bean with name 'projectingArgumentResolverBeanPostProcessor'
我在我的项目中设置我的网络安全,但我看到一个错误。
这是错误
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[=13=](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());
}
}
用户安全 class 是:
@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”注释程序时运行
我以前用过这个鳕鱼,它工作正常。
您最近 spring 更新了吗?在以前的版本中,空 MethodSecurityMetadataSource
是可以的,但现在他们在讨论此更改的地方添加了 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
要修复它,请在 @EnableGlobalMethodSecurity
注释属性中启用其中一个元数据源,或者,如果像我一样,您正在使用某种 GlobalMethodSecurityConfiguration
,请确保方法 customMethodSecurityMetadataSource
returns not-null
您遇到此问题是因为您没有正确注释。您应该这样添加:@EnableGlobalMethodSecurity(prePostEnabled = true)
我在我的项目中设置我的网络安全,但我看到一个错误。 这是错误
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[=13=](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());
}
} 用户安全 class 是:
@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”注释程序时运行 我以前用过这个鳕鱼,它工作正常。
您最近 spring 更新了吗?在以前的版本中,空 MethodSecurityMetadataSource
是可以的,但现在他们在讨论此更改的地方添加了 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
要修复它,请在 @EnableGlobalMethodSecurity
注释属性中启用其中一个元数据源,或者,如果像我一样,您正在使用某种 GlobalMethodSecurityConfiguration
,请确保方法 customMethodSecurityMetadataSource
returns not-null
您遇到此问题是因为您没有正确注释。您应该这样添加:@EnableGlobalMethodSecurity(prePostEnabled = true)