Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Important points

Pragya Keshap answered on February 20, 2023 Popularity 3/10 Helpfulness 1/10

Contents


More Related Answers


Important points

0

You should annotate the Main class or Bootstrap class with the @SpringBootApplication; this will allow you to run as a JAR with embedded web server Tomcat. If you want, you can change that to Jetty or Undertow.

2. The @SpringBootApplication is a combination of three annotations @Configuration (used for Java-based configuration), @ComponentScan (used for component scanning), and @EnableAutoConfiguration (used to enable auto-configuration in Spring Boot).

3. The @EnableAutoConfiguration annotations enable auto-configuration features of Spring Boot, which configures modules based on the presence of certain classes on the classpath. For example, if Thymeleaf JAR is present in classpath and Spring MVC is enabled like using a spring-boot-web-starter package, then it can automatically configure template resolver and view resolver for you.

4. The @EnableAutoConfiguration annotation is based on @Conditional annotation of Spring 4.0, which enables conditional configuration.

5. In the case of auto-configuration, manually declared beans can override beans automatically created by the auto-configuration feature. This is achieved by using @ConditionalOnMissingBean of Spring 4.0

6. If you are using @EnableAutoConfiguration classes, then you can selectively exclude certain classes from auto-configuration by using exclude as shown below:

@EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class)

7. The @SpringBootApplication annotation also provides aliases to customize the attributes of @EnableAutoConfiguration and @ComponentScan annotations.

That's all about the difference between @SpringBootApplication and @EnableAutoConfiguration annotations of Spring Boot you normally use in Java applications. As you have learned, the @SpringBootApplication makes it easy to enable auto-configuration and create a Bootstrap class by reducing the number of annotations you normally need, I mean, instead of 3 annotations, you just need one.

But, if you need more control over autoconfiguration, then you should use @EnableAutoConfiguration, which allows you to exclude classes from auto-configuration.

Read more: https://www.java67.com/2018/05/difference-between-springbootapplication-vs-EnableAutoConfiguration-annotations-Spring-Boot.html#ixzz7tpuzsyce

Popularity 3/10 Helpfulness 1/10 Language whatever
Source: Grepper
Link to this answer
Share Copy Link
Contributed on Feb 20 2023
Pragya Keshap
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.