Prasanna
Prasanna

Reputation: 91

Difference between @EnableAutoConfiguration vs @SpringBootConfiguration ( @AutoConfigurationPackage vs @Configuration )

I know that when we annotate a java class as @SpringBootApplication we will have internally annotations @EnableAutoConfiguration and @SpringBootConfiguration but i'm confused what is the difference between them.

I am very much new to spring boot, Can someone please elaborate on this.

Upvotes: 2

Views: 7938

Answers (2)

Krishna Gangaraju
Krishna Gangaraju

Reputation: 529

it is meta annotation @SpringBootApplication will have other annotations

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SpringBootApplication.java

if @SpringBootApplication is not there applications need to use other annotations on Main class

Upvotes: 0

vmilojevic
vmilojevic

Reputation: 119

public @interface SpringBootConfiguration

Indicates that a class provides Spring Boot application @Configuration. Can be used as an alternative to the Spring's standard @Configuration annotation so that configuration can be found automatically (for example in tests).

from: SpringBootConfiguration docs

public @interface EnableAutoConfiguration

Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need.

from: EnableAutoConfiguration docs

So what is the difference?

@SpringBootConfiguration annotation tells us that a class is a configuration class, and @EnableAutoConfiguration automatically configures the Spring application based on its included jar files.

Upvotes: 4

Related Questions