我在我的项目中设置我的网络安全,但我看到一个错误。这是错误
org.springframework.beans.factory.BeanCreationException:在类路径资源[org/springframework/data/web/config/ProjectingArgumentResolverRegistrar.class]中定义的名称为“projectingArgumentResolverBeanPostProcessor”的bean创建错误:bean实例化之前的BeanPostProcessor失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“metaDataSourceAdvisor”的 bean 时出错:设置构造函数参数时无法解析对 bean“methodSecurityMetadataSource”的引用;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [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。
我的鳕鱼是:
@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());
}
用户安全类是:
@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”注释程序正确运行时,我之前使用过这个代码并且它工作正常。