0

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,

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.

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Yes, I can remove it, but I'm seeking a reason to appear an error. Because for some people it is working properly. Do you know the reason?
I guess it is a check in the plugin from the IDE
wow, brilliant. Thank you @Jens for the support. Now I can accept your answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.