Spring Boot - Auto-configuration with @SpringBootApplication

[Last Updated: Oct 16, 2018]

Since @EnableAutoConfiguration and @ComponentScan are likely to be frequently used by the developers, Spring Boot provides a convenient equivalent shortcut (a meta-annotation) for these two annotations: @SpringBootApplication.

Example using @SpringBootApplication

<project ...>
public class MyBean {
   public String getMessage () {
       return "a message from MyBean";
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

public class MyWebController {

   private MyBean myBean;

   public String theHandler () {
       return myBean.getMessage();

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;

public class EnabledAutoConfigExample {

   public static void main (String[] args) {, args);

Output in browser

Just like @ComponentScan elements: basePackageClasses and basePackages, @SpringBootApplication annotation provides scanBasePackageClasses and scanBasePackages to be specified if the scan base path is not same as of this configuration class.

Example Project

Dependencies and Technologies Used:

  • Spring Boot 1.4.2.RELEASE
    Corresponding Spring Version 4.3.4.RELEASE
  • Spring Boot Web Starter : Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container.
  • JDK 1.8
  • Maven 3.3.9

Spring Boot Annotation Select All Download
  • spring-boot-annotation
    • src
      • main
        • java
          • com
            • logicbig
              • example

    See Also