Spring or Spring Boot - that is the question!

23.04.2020 -

From time to time I am asked what the difference is between Spring and Spring Boot. With this article, I would like to shed some light on the subject.

The fact that the terms "Spring","Spring Framework" and "Spring Boot" are often used interchangeably does not make the distinction any easier. I would therefore like to differentiate between the "Spring Framework" and "Spring Boot ". The term "Spring", on the other hand, includes both and encompasses everything that the Spring world as a whole has to offer.

The Spring framework

Spring FrameworkAccording to official documentation, the Spring Framework to "a comprehensive programming and configuration model for modern Java-based enterprise applications - on all possible deployment platforms. [...] Spring focuses on 'wiring' enterprise applications without unnecessary ties to specific deployment environments"
(Source: https://spring.io/projects/spring-framework)

The Spring Framework is therefore a collection of tools for the development of business applications. Its core functionalities include dependency injection, events, resources, internationalization, data access with transactions, integration and much more.

Spring Boot

Spring Boot is based on the Spring Framework and is designed to enable very simple development of executable and production-ready Spring applications. This is achieved through an auto-configuration mechanism that pre-configures the tools from the Spring Framework, as well as a range of other tools, in a meaningful way. By the way, "configuration " here refers to the configuration of the Spring beans, which determines which beans are available for dependency injection and how they are "wired" together - and not the configuration properties that are maintained in application.properties, for example.

For example, Spring Boot Web comes with an embedded Tomcat container by default that runs on port 8080 - without you having to configure anything yourself. You can change the port by simply entering a different value in the application.properties under server.port. You can also use a different servlet container instead of Tomcat. All you have to do is exclude Tomcat in the Maven or Gradle configuration and add the dependency for another container, such as Jetty.

Other aspects such as Spring Data, Spring Security etc. can also be added to an application by simply including dependencies in the build configuration. Spring Boot then recognizes that a functionality should be activated simply by the presence of certain classes or configuration properties and automatically creates the necessary Spring Beans. If, for example, HikariCP is present in the class path, a HikariDataSource bean is automatically generated. If DBCP2 is in the classpath instead (and Hikari is excluded), the DBCP2 connection pool is used for the data source instead of Hikari. Hibernate and transactions are automatically activated for Spring Data JPA.

Furthermore, Spring Boot registers a whole series of @PropertySources, so that application properties are automatically read from no less than 17 different sources - including application.properties, application.yaml, command line parameters, OS system variables, Java system properties and many more. The complete list can be found here:
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/.

The spring-boot-maven-plugin packs the application together with all required libraries into a "fat jar", which can be started with java -jar my-app.jar.

Last but not least, Spring Boot comes with very comprehensive dependency management, in which the versions for the Spring libraries, but also for many 3rd party libraries (e.g. Apache Commons, Hibernate, JUnit, Mockito and many more) are coordinated and maintained. This means you can bring these libraries into your project without having to maintain their versions yourself.

With the Spring Initializr, you can create a new Spring Boot project in no time at all, with which you can start development directly and without any initial effort. The Initializr is available as a web UI, command line tool, for HTTP clients such as cURL, or even directly from IDEs (e.g. IntelliJ IDEA).

Conclusion

The Spring Framework is a toolset for developing enterprise applications for all possible deployment platforms. Spring Boot is based on this and offers many convenient functions that enable a quick project start and are sensibly preconfigured, but can still be very flexibly adapted to the respective requirements via configuration.

If you want to know more about Spring Boot and the details of the auto-configuration mechanism, you can find a detailed explanation here:
https://www.marcobehler.com/guides/spring-boot.

Back to overview

Write a comment

Your e-mail address will not be published. Required fields are marked with *

*Mandatory fields

*