Spring Security 中的 WebSecurityConfigurerAdapter 类错误

问题描述 投票:0回答:1

我使用 Spring Security 来登录我的应用程序。我使用了 Maven、Spring Boot 3.2.3 和 Java 17。编译我的项目时出现以下错误。

java: cannot find symbol  

symbol:   class WebSecurityConfigurerAdapter

  location: package org.springframework.security.config.annotation.web.configuration

它说找不到

WebSecurityConfigurerAdapter
我也添加了依赖项,但我仍然收到该错误

我使用 intelliji 作为 IDE。下面我提供了我尝试使用 Spring security 的代码

package com.xyz.productdashboardlogin;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter{
}

下面我将提供我的

Pom.xml
文件。

  <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.xyz</groupId>
    <artifactId>Product-Dashboard-Login</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Product-Dashboard-Login</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>

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

        </dependency>
        

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

WebSecurityConfigurerAdapter
不适用于较新版本的 Spring 吗? 我是 Spring Boot 的初学者。您能帮我解决这个问题吗?

java spring spring-boot maven spring-security
1个回答
0
投票

在 Spring Security 5.7.0 中,Spring 弃用了 WebSecurityConfigurerAdapter。 他们鼓励基于组件的安全配置。

© www.soinside.com 2019 - 2024. All rights reserved.