Running a Spring Boot application

So far, we have a bare bones project. There isn't much code. However, http://start.spring.io creates a single Application class; let's look at that first:

package learningspringboot;

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

@ComponentScan
@EnableAutoConfiguration
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Let's break this down:

  • @ComponentScan: This tells Spring to look for classes with @Component, @Configuration, @Repository, @Service, and @Controller and wire them into the app context as beans. By ...

Get Learning Spring Boot now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.