当前位置: 首页 > 面试题库 >

Spring Security Configuration @Order不是唯一异常

龙华翰
2023-03-14
问题内容

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

2015年11月4日14:35:23.792警告[RMI TCP Connection(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'

问题答案:

我发现了错误…没人在摘要中发布导入内容。我们正在使用多模块项目设置,而IntelliJ无法识别Spring注释,因此使用了

org.apache.logging.log4j.core.config.Order

代替

org.springframework.core.annotation.Order

由于Spring无法解析正确的注释,因此这两种配置均假定默认值为100。



 类似资料:
  • 问题内容: 我得到错误 我不知道这是怎么回事。 问题答案: 尝试

  • 问题内容: 下面是我的代码,我只想显示我在sqlite数据库中插入的数据到文本视图,但是我遇到这个错误,说id不是唯一的。 这是我的整个Java代码。谢谢 :) 问题答案: 好吧,我认为这个项目在您首次运行时效果很好。当您第二次运行它时,由于是您的ID为1的行已被插入到您的数据库中,因此会出现错误。 要消除错误,请执行以下任一操作:

  • 问题内容: 你能帮我一下吗?我有这个SQL查询: 它以某种方式说 问题答案: 您似乎从同一张表中选择了两次。这些事件中的每一个都需要有自己的别名: 请注意,我还为该表添加了缺少的别名。

  • 这是我的限制: 该查询证明约束实际上不起作用: 下面是输出: 为什么唯一性没有被强制执行?

  • 时间戳在所有行中是否唯一? 上面有唯一的索引吗?

  • 我在oracle数据库中有一个表,我们称之为Task,我要在其中插入批处理过程中的一堆行。 我在4列上设置了唯一的约束,其中一列是可为null的(locationId、shelfId、itemId和batchId),其中一列是可为null的(shelfId) 在解析CSV文件的值(从另一个数据库表读取)的过程中,这些值以100为一组进行批处理,并发布到一个API以便进一步解析(以上面提到的表的格式