@SpringBootApplication annotation example in Spring Boot

In this post, we will see @SpringBootApplication annotation example in Spring Boot.

 

  • This annotation is a combined form of @SpringBootConfiguration,@EnableAutoConfiguration, and @ComponentScan.
  • We use this annotation with class.
  • This annotation introduced in Spring  1.2, available in org.springframework.boot.autoconfigure package.
  • Optional elements  (exclude, excludeName, ScanBasePackageClasses, ScanBasePackages).

 

@SpringBootApplication annotation example in Spring Boot.

SpringMain.java

 

TestContoller.java

 

The directory structure should look likes below.

@SpringBootApplication annotation example in Spring Boot

/SpringBootAnnotExamp/src/main/resources/application.properties

server.port = 9093

@SpringBootApplication annotation example in Spring Boot

Let’s modify the SpringMain.java. We will use @SpringBootConfiguration, @EnableAutoConfiguration and @ComponentScan instead of @SpringBootApplication.

SpringMain.java

 

Run this class and hit the rest URI on the browser.

That’s all about @SpringBootApplication annotation example in Spring Boot.

You may like.

 

Check @SpringBootApplication annotation docs.

 

 

Top