无法解析符号WebSecurityConfigurerAdapter

时间:2019-01-14 08:03:48

标签: spring-boot spring-security

我尝试在Java应用程序中创建基本身份验证。对于他们,我在gradle文件中使用了此依赖项

dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: '1.5.9.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.9.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '1.3.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version: '1.4.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb', version: '1.5.9.RELEASE'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.7'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.7'
compile group: 'org.apache.logging.log4j', name: 'log4j-web', version: '2.7'
compile('org.hibernate:hibernate-core')    
testCompile group: 'junit', name: 'junit', version: '4.12'

}

当我实现扩展类WebSecurityConfigurerAdapter的想法时,显示错误无法解析符号WebSecurityConfigurerAdapter 并突出显示红色代码。 enter image description here

我也尝试过使用下一个依赖项

compile group: 'org.springframework.boot', name: 'spring-security-core', version: '5.0.0.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-security-web', version: '5.0.0.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-security-config', version: '5.0.0.RELEASE'

实施扩展类WebSecurityConfigurerAdapter需要为gradle文件提供哪些依赖项?

2 个答案:

答案 0 :(得分:2)

该类将位于spring-security-config

中的org.springframework.security组中,而不是 org.springframework.boot 中。
compile group: "org.springframework.security", name: "spring-security-config", version: "$springSecurityVersion"

尽管,正如评论所暗示的,

示例build.gradle看起来像

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: "org.springframework.boot"

dependencies {

    compile group: "org.springframework.security", name: "spring-security-core", version: "$springSecurityVersion"
    compile group: "org.springframework.security", name: "spring-security-config", version: "$springSecurityVersion"
    compile group: "org.springframework.security", name: "spring-security-web", version: "$springSecurityVersion"
    compile group: "org.springframework.security", name: "spring-security-oauth2-jose", version: "$springSecurityVersion"
    compile group: "org.springframework.security", name: "spring-security-oauth2-resource-server", version: "$springSecurityVersion"
    compile group: "org.springframework.boot", name: "spring-boot-starter-web", version: "$springBootVersion"
    compile group: "org.springframework.boot", name: "spring-boot-starter-security", version: "$springBootVersion"
    compile group: "org.springframework.boot", name: "spring-boot-starter-thymeleaf", version: "$springBootVersion"
    compile group: "org.thymeleaf.extras", name: "thymeleaf-extras-springsecurity5", version: "$thymeleafExtrasSpringSecurityVersion"

    testCompile group: "org.springframework.boot", name: "spring-boot-starter-test", version: "$springBootVersion"
    testCompile group: "org.springframework.security", name: "spring-security-test", version: "$springSecurityVersion"
}

答案 1 :(得分:-1)

在扩展 @EnableWebSecurity 之前尝试在类级别使用 WebSecurityConfigurerAdapter 进行注释。

import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
相关问题