In this section, we cover, what Spring and Spring Boot actually are, how they relate and how to get started.
In progress - Your feedback and participation are encouraged!
In short, Spring Boot is a new Framework with an opinionated view of building production-ready applications using the standard Spring Framework. Building applications with the Spring Framework used to be a tedious task; especially when starting a new project. Spring consists of multiple modules which you can use individually or integrate each other. The downside is that you always had to do it manually. Also, in many cases, modules were not shipped with default configurations of out the box - they assume you connect them how you like. So, you had to connect everything by yourself too, be it in XML or with Java annotations. That changed with Spring Boot.
Spring Boot is a way to start new applications and use the world of Spring modules with defaults which make sense.
Its Features:
Last week I was chatting with a friend, and he told me how lucky he is that a part of their system moved to using Spring Boot. It made his life easier with development and testing. He actually loved writing tests now. However, one of his colleagues did question the decision to go with Spring Boot because Spring Boot is meant to be used with Docker and for microservices only. I was baffled, but it seems there’s a lot of confusion what Spring Boot actually is and when to use it. This article does shed some light on it.
Is Spring Boot for Microservices only?
Yes, I think you can, and I outlined my reasons for that a while ago in Can You Learn Spring Boot without Prior Knowledge of the Spring Framework?. Learning the Core of Spring is pretty straight forward. You can do it on your own as I outlined in the article or use my free eMail course or learn it in Spring Boot: How To Get Started and Build a Microservice as I will cover it in the upcoming second edition.
The easiest way to start a new project is by using the Spring Initializer.
The second way is to create a Maven pom.xml file or Gradle if you prefer Gradle.
Let’s create a simple Hello World web application:
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cde.codeboje.springbootbook</groupId>
<artifactId>comment-store</artifactId>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M3</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
The magic is done by including the spring-boot-starter-parent and by adding a starter module, like spring-boot-starter-web for web applications.
Now, let’s create the simple application. It does have one endpoint at ROOT and will return Hello World! when you call it.
package de.codeboje.springbootbook.commentstore;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
@RestController
@SpringBootApplication
public class CommentStoreApp {
@RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args)
throws Exception {
SpringApplication.run(CommentStoreApp.class, args);
}
}
Just a few lines of code and you are up and running.
Instead of writing the same over and over again, I collected some resources for getting started with the basics.
If you have experience with the Spring Framework and are a seasoned dev, you can go free and learn with the Spring Boot Reference Docs.
If you value your time and are looking for a brief starting guide, read Spring Boot: How To Get Started and Build a Microservice. It covers the essentials and is a fast paced read. Sample chapters are publicy available.
Courses:
Disclaimer: Some of the links can be affiliate links or link to my own products.