Spring security 使用JavaConfig的Spring Security 3.2.3版本

Spring security 使用JavaConfig的Spring Security 3.2.3版本,spring-security,spring-java-config,Spring Security,Spring Java Config,我有一个用XML配置的Spring安全性,可以正常工作。现在,我试图将其仅用JavaConfig表示,以便完全摆脱XML配置 我查看了参考文档、许多博客和支持请求,但仍然找不到解决方案 它给了我以下例外情况: Could not autowire field: private org.springframework.security.web.FilterChainProxy com.thalasoft.learnintouch.rest.config.WebTestConfiguration.s

我有一个用XML配置的Spring安全性,可以正常工作。现在,我试图将其仅用JavaConfig表示,以便完全摆脱XML配置

我查看了参考文档、许多博客和支持请求,但仍然找不到解决方案

它给了我以下例外情况:

Could not autowire field: private org.springframework.security.web.FilterChainProxy
com.thalasoft.learnintouch.rest.config.WebTestConfiguration.springSecurityFilterChain;
遗憾的是,我求助于在这里发布我自己的请求

守则:

@配置
@ComponentScan(basePackages={“com.thalasoft.learnTouch.rest”})
公共类WebTestConfiguration{
@自动连线
私有WebApplicationContext WebApplicationContext;
@自动连线
私有过滤链Proxy springSecurityFilterChain;
}
公共类SecurityWebApplicationInitializer扩展了AbstractSecurityWebApplicationInitializer{
}
公共类WebInit实现WebApplicationInitializer{
私有静态记录器Logger=LoggerFactory.getLogger(WebInit.class);
@凌驾
启动时公共void(ServletContext ServletContext)引发ServletException{
registerListener(servletContext);
registerDispatcherServlet(servletContext);
registerJspServlet(servletContext);
}
私有无效注册表列表器(ServletContext ServletContext){
//创建根应用程序上下文
AnnotationConfigWebApplicationContext appContext=createContext(ApplicationConfiguration.class,WebSecurityConfiguration.class);
//设置应用程序显示名称
setDisplayName(“LearnTouch”);
//创建由所有servlet和过滤器共享的Spring容器
addListener(新的ContextLoaderListener(appContext));
}
私有无效注册表DispatcherServlet(ServletContext ServletContext){
AnnotationConfigWebApplicationContext webApplicationContext=createContext(WebConfiguration.class);
ServletRegistration.Dynamic dispatcher=servletContext.addServlet(“dispatcher”,新DispatcherServlet(webApplicationContext));
dispatcher.setLoadOnStartup(1);
设置mappingConflicts=dispatcher.addMapping(“/”);
如果(!mappingConflicts.isEmpty()){
for(字符串映射冲突:映射冲突){
logger.error(“映射冲突:+mappingConflict”);
}
抛出新的非法状态异常(
“servlet无法映射到“/”);
}
}
私有无效注册表JSPServlet(ServletContext ServletContext){
}
专用注释ConfigWebApplicationContext createContext(最终类…模块){
AnnotationConfigWebApplicationContext appContext=新的AnnotationConfigWebApplicationContext();
appContext.register(模块);
返回appContext;
}
}
@配置
@启用Web安全性
公共类WebSecurity配置扩展了WebSecurity配置适配器{
@自动连线
CustomAuthenticationProvider CustomAuthenticationProvider;
@凌驾
受保护的无效配置(AuthenticationManagerBuilder auth)引发异常{
authenticationProvider(customAuthenticationProvider);
}
@豆子
公共授权筛选器Proxy springSecurityFilterChain(){
DelegatingFilterProxy filterProxy=新的DelegatingFilterProxy();
回流过滤;
}
@凌驾
public void configure(WebSecurity web)引发异常{
忽略().antMatchers(“/resources/**”);
}
@凌驾
受保护的无效配置(HttpSecurity http)引发异常{
http.authorizeRequests();
http.authorizeRequests().antMatchers(“/admin/login”、“/admin/logout”、“/admin/denied”).permitAll()
.antMatchers(“/admin/**”).hasRole(“角色\管理员”)
.及()
.formLogin()
.loginPage(“/admin/login”)
.defaultSuccessUrl(“/admin/list”)
.failureUrl(“/admin/denied?failed=true”)
.及()
.rememberMe();
http.logout().logoutUrl(“/admin/logout”).logoutSuccessUrl(“/admin/login”).deleteCookies(“JSessID”);
}
}
我希望摆脱的XML配置:


更新:

我添加了一个配置指令:

@配置
公共类SecurityWebApplicationInitializer扩展了AbstractSecurityWebApplicationInitializer{
}
以及明确的进口指令:

@Import({SecurityWebApplicationInitializer.class})
公共类WebSecurity配置扩展了WebSecurity配置适配器{
}
但例外情况仍然完全相同

我正在运行SpringSecurity3.2.4.RELEASE和Spring3.2.9.RELEASE


如果您有任何建议,我们欢迎。

我从安全配置中删除了这个bean定义,它似乎已经解决了这个问题

@Bean
public DelegatingFilterProxy springSecurityFilterChain() {
    DelegatingFilterProxy filterProxy = new DelegatingFilterProxy();
    return filterProxy;
}