我试图在我的Spring Security配置中注册多个过滤器,但是我总是得到相同的异常:
04-Nov-2015 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() …Run Code Online (Sandbox Code Playgroud)