我试图在我的 Spring 安全配置中注册多个过滤器,但我总是遇到相同的异常:
2015 年 11 月 4 日 14:35:23.792 警告 [RMI TCP 连接 (3)-127.0.0.1] org.springframework.web.context.support.AnnotationConfigWebApplicationContext.refresh 在上下文初始化期间遇到异常 - 取消刷新尝试 org.springframework.beans .factory.BeanCreationException:创建名为“org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration”的 bean 时出错:注入自动装配的依赖项失败;嵌套异常是 java.lang.IllegalStateException:WebSecurityConfigurers 上的@Order 必须是唯一的。 100 的订单已被使用,因此它也不能用于 com.payment21.webapp.MultiHttpSecurityConfig\(ApiWebSecurityConfigurationAdapter\)\(EnhancerBySpringCGLIB\)$35c79fe4@1d381684。
由于我自己的尝试没有奏效,我尝试了与 Spring Security 参考 中所示 完全相同的代码:
@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();
}
}
}
为了隔离错误,我尝试用基于 Java 的方法替换 web.xml,但它也没有用。我不知道出了什么问题,是医生错了吗?我的应用程序中的某些东西会扰乱配置吗?系统启动正常,除非我注册第二个 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'
原文由 Journeycorner 发布,翻译遵循 CC BY-SA 4.0 许可协议
我发现了错误……没有人在片段中发布导入。我们正在使用多模块项目设置,而 IntelliJ 无法识别 Spring 注释并使用
代替
由于 Spring 没有解析正确的注解,它假设两种配置的默认值为 100。