我试着在我的春季安全配置来注册多个过滤器,但我总是得到相同的异常:春季安全配置@Order不是唯一的例外
04 - 11月 - 2015年14:35:23.792警告[RMI TCP连接(3)-127.0.0.1] org.springframework.web.context.support.AnnotationConfigWebApplicationContext.refresh 异常上下文初始化过程中遇到 - 消除 刷新尝试 org.springframework.beans.factory.BeanCreationException:错误 创建名称为 的bean'org.springframework.security.config.annotation.web.confi guration.WebSecurityConfiguration': 注入自动装配依赖失败;嵌套的异常是 java.lang.IllegalStateException:WebSecurityConfigurers上的@Order必须是唯一的 。 100的订单已被使用,所以它不能用于 com.payment21.webapp.MultiHttpSecurityConfig$ApiW[email protected]1d381684 。
由于我自己的努力没有工作,我试过完全相同的代码如图所示Spring Security reference:
@EnableWebSecurity
public class MultiHttpSecurityConfig {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER", "ADMIN");
}
@Configuration
@Order(1)
public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/api/**")
.authorizeRequests()
.anyRequest().hasRole("ADMIN")
.and()
.httpBasic();
}
}
@Configuration
public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin();
}
}
}
要找出错误我试图取代通过web.xml中基于Java的方法,但它也没有工作。我不知道什么是错,文件是错的?我的应用程序中的某些东西可能与配置混乱吗?系统正常启动,除非我注册第二个WebSecurityConfigAdapter。
那是我的依赖关系:
compile 'org.springframework:spring-webmvc:4.2.2.RELEASE'
compile 'org.springframework:spring-messaging:4.2.2.RELEASE'
compile 'org.springframework:spring-websocket:4.2.2.RELEASE'
compile 'org.springframework:spring-aop:4.2.2.RELEASE'
compile'javax.servlet:javax.servlet-api:3.0.1'
compile 'org.springframework.security:spring-security-web:4.0.3.RELEASE'
compile 'org.springframework.security:spring-security-config:4.0.3.RELEASE'
这是一些深层次的东西.. :-) –
你是如何解决这个问题的?编译IDEA时遇到确切的问题。我的应用程序中没有@Order,但它仍然对WebSecurityConfigurerAdapter非常困惑! –