spring-bootspring-mvcspring-securityspring-security-config

Cannot resolve symbol 'WebSecurityConfigurerAdapter' - Method does not override method from its superclass


I am encountering an issue in my Spring Security configuration where the compiler cannot resolve the symbol 'WebSecurityConfigurerAdapter'. Additionally, I am facing errors stating that methods do not override methods from their superclass. The relevant code snippet is as follows:

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 Version: 3.2.1

ERROR:

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

Solution

  • I guess the spring-boot version that you are using is 3.x and started from this version the WebSecurityConfigurerAdapter was removed and you have to follow next one article to replace deprecated/removed things spring-security-without-the-websecurityconfigureradapter

    Also Configuration part of documentation that will help you to get rid of old configuration.

    Here on stackOverflow are a lot of related topic about this kind of migration. As a start you can check my related answer to this question updating-to-latest-spring-security-replacing-deprecated-methods