【问题标题】:How to resolve DefaultSecurityFilterChain in spring security?如何解决 Spring Security 中的 DefaultSecurityFilterChain?
【发布时间】:2020-06-19 11:42:05
【问题描述】:

我遇到了这个问题——org.springframework.security.web.DefaultSecurityFilterChain 类型无法解决。它是从所需的 .class 文件中间接引用的。


import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.User.UserBuilder;

@Configuration
@EnableWebSecurity
public class DemoSecurityconfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        UserBuilder users=User.withDefaultPasswordEncoder();
        auth.inMemoryAuthentication()
            .withUser(users.username("John").password("john123").roles("EMPLOYEE"))
            .withUser(users.username("Mac").password("mac123").roles("MANAGER"))
            .withUser(users.username("Lily").password("lily123").roles("ACCOUNTANT"));
    }

}```

【问题讨论】:

    标签: java spring maven spring-security


    【解决方案1】:

    DefaultSecurityFilterChain 位于spring-security-web-x.y.z.RELEASE.jar。此错误很可能是因为无法从类路径中找到此类。

    所以去类路径检查这个jar是否真的包含。如果没有,并且您正在使用spring-boot,您可以使用spring-boot-starter-security starter,它将自动包含它。

    如果您不使用 spring-boot,请确保包含以下依赖项。 对于Mavenpom.xml 应包括

     <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
        </dependency>
    

    对于Gradlebuild.gradle 应该包括:

    dependencies {
        compile "org.springframework.security:spring-security-web"
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-10
      • 1970-01-01
      • 1970-01-01
      • 2015-04-26
      • 2015-09-11
      • 2021-07-12
      • 2015-05-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多