Card 01/ 06

ConceptDifficulty: Intermediate1 min

Spring Boot: What It Adds to Spring

The same Spring underneath, minus the setup you would otherwise write by hand.

Spring Boot is Spring with the setup done for you. It looks at the libraries on your application's classpath (the set of libraries the program can load) and at your own configuration, and creates the beans a typical application with those libraries needs. You then write configuration only where your application differs from the typical case.

A plain Spring MVC application (Spring's framework for web applications) needs a DispatcherServlet, the component that receives every web request and passes it to your code, registered with a web server. The server is installed and configured separately, and the versions of Spring MVC, Jackson (the JSON library) and the server all have to be chosen by hand so that they agree.

A Spring Boot application needs one dependency and one annotation:

java
@SpringBootApplication
public class RideServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(RideServiceApplication.class, args);
    }
}

Everything the plain setup did still happens: the DispatcherServlet is still registered and a server still starts. What disappears is only the part where you configure it yourself. Boot starts the server on port 8080, for instance, because most web applications want one there; if yours needs 9090, you set server.port=9090 and write nothing else.

So Boot is not a different framework standing in for Spring. When something in a Boot application behaves unexpectedly, the question to ask is which bean Boot created for you, and on what condition.