Spring Boot - Auto-configuration with @SpringBootApplication

[Updated: Dec 6, 2016, Created: Dec 6, 2016]

Since @EnableAutoConfiguration and @ComponentScanare 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 Web Starter 1.4.2.RELEASE: Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container.
    Corresponding Spring version: 4.3.4.RELEASE
  • JDK 1.8
  • Maven 3.3.9

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

See Also