Spring Boot 无法解析符号WebSecurityConfigurerAdapter

9o685dep  于 2023-04-30  发布在  Spring
关注(0)|答案(3)|浏览(707)

我尝试在我的Java应用程序中创建Basic Auth。对于他们,我在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'

}
当i实现扩展类WebSecurityConfigureAdapter想法显示错误Cannot resolve symbol WebSecurityConfigureer Adapter并突出显示代码红色。

我也试着使用下一个依赖

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文件?

uttx8gqw

uttx8gqw1#

这个类将位于org.springframework.security组中,而不是 * org组中。SpringFramework在工件spring-security-config下 Boot *

compile group: "org.springframework.security", name: "spring-security-config", version: "$springSecurityVersion"

不过,正如评论所说,
作为样品构建。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"
}
6l7fqoea

6l7fqoea2#

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

import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
rqmkfv5c

rqmkfv5c3#

参见https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter
我相信websecurityconfigureradapter已经在最新的spring Boot 库中删除了。

相关问题