无法解析符号“WebSecurityConfigurerAdapter” - 方法不会覆盖其超类中的方法

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

我在 Spring Security 配置中遇到问题,编译器无法解析符号“WebSecurityConfigurerAdapter”。此外,我遇到错误,指出方法不会覆盖其超类中的方法。相关代码片段如下:

package com.shubham.dev.discoveryserver.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Value("${app.eureka.username}")
    private String username;
    @Value("${app.eureka.password}")
    private String password;

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .passwordEncoder(NoOpPasswordEncoder.getInstance())
                .withUser(username).password(password)
                .authorities("USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf(csrf->csrf.disable())
                .authorizeRequests().anyRequest()
                .authenticated()
                .and()
                .httpBasic(Customizer.withDefaults());
    }
}

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.shubham.dev</groupId>
        <artifactId>Inventory-Management</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>discovery-server</artifactId>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        


    </dependencies>

</project>

SpringBoot版本:3.2.1

错误:

Cannot resolve symbol 'WebSecurityConfigurerAdapter':8 
Cannot resolve symbol 'WebSecurityConfigurerAdapter':12  
Method does not override method from its superclass:19 
Method does not override method from its superclass:27
spring-boot spring-mvc spring-security spring-security-oauth2 spring-security-config
1个回答
0
投票

我猜您正在使用的

spring-boot
版本是
3.x
并且从这个版本开始
WebSecurityConfigurerAdapter
已被删除,您必须按照下一篇文章来替换已弃用/删除的内容 没有 websecurity 配置适配器的 spring-security

还有配置文档的一部分,将帮助您摆脱旧的配置。

stackOverflow 上有很多关于这种迁移的相关主题。首先,您可以检查我对此问题的相关答案更新到最新的spring-security-replacing-deprecated-methods

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