java避免使用orderby_java – Spring安全配置@Order不是唯一的例外

我试图在我的Spring Security配置中注册多个过滤器,但是我总是得到相同的异常:

04-Nov-2015 14:35:23.792 WARNING [RMI TCP Connection(3)-127.0.0.1]

org.springframework.web.context.support.AnnotationConfigWebApplicationContext.refresh

Exception encountered during context initialization – cancelling

refresh attempt

org.springframework.beans.factory.BeanCreationException: Error

creating bean with name

‘org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration’:

Injection of autowired dependencies failed; nested exception is

java.lang.IllegalStateException: @Order on WebSecurityConfigurers must

be unique. Order of 100 was already used, so it cannot be used on

com.payment21.webapp.MultiHttpSecurityConfig$ApiWebSecurityConfigurationAdapter$$EnhancerBySpringCGLIB$$35c79fe4@1d381684

too.

由于我自己的尝试不起作用,我尝试了完全相同的代码,如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();

}

}

}

为了隔离错误,我尝试用基于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'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值