Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Redundant declaration: @SpringBootApplication already applies given @ComponentScan

I created a spring boot application(3.0.1). Then I connected the Postgres database and executed it. The application is up on server 8080 smoothly. then I added below-mentioned annotations.

@EnableAutoConfiguration
@ComponentScan

whole file,

package com.example.SpringRecap;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan

public class SpringRecapApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringRecapApplication.class, args);
    }

    @GetMapping("/")
    public void Employee() {

    }


}

Now, below mentioned error are appeared,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Redundant declaration: @SpringBootApplication already applies @EnableAutoConfiguration
Redundant declaration: @SpringBootApplication already applies given @ComponentScan

Image of InteliJ:

Image of InteliJ:

If anyone knows the reason, please help me. If further information is needed to solve the problem please put a comment here.
Thank You.

>Solution :

below mentioned error are appeared: This means that you can remove @ComponentScan and @EnableAutoConfiguration.

As the documentation on spring mentioned, it is included in @SpringBootApplication:

Many Spring Boot developers like their apps to use auto-configuration, component scan and be able to define extra configuration on their "application class". A single @SpringBootApplication annotation can be used to enable those three features, that is:

    @EnableAutoConfiguration: enable Spring Boot’s auto-configuration mechanism
    @ComponentScan: enable @Component scan on the package where the application is located (see the best practices)
    @Configuration: allow to register extra beans in the context or import additional configuration classes 

It is a check in the plugin of Intellij. Also see https://youtrack.jetbrains.com/issue/IDEA-177632

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading