My Favorite Features of Spring Boot

Spring Boot is a lightweight framework that takes most of the work out of configuring Spring-based applications. It follows “Opinionated Defaults Configuration” approach to reduce developer effort.

In this article, I will talk about some of my favorite features:

Endpoints

Spring Boot allows you to monitor and interact with your application. It includes several built-in endpoints and you can add your own as well. Auditing, health and metrics gathering can be automatically applied to your application. For example, the health endpoint will be mapped to /health, which displays application health information.

We can enable the endpoints by simply adding spring-boot-starter-actuator to the pom.

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-actuator</artifactId>

    <version>1.5.7.RELEASE</version>

</dependency>

Check out the complete list of endpoints provided by Spring Boot.

Auto-configuration

Spring Boot auto-configuration represents a way to automatically configure a Spring application based on the dependencies that are present on the classpath. This can make development faster and easier.

For example, if h2 is on your classpath, then spring boot will auto-configure an in-memory database. You do not have to manually configure any database connection beans.

Spring Boot’s auto-configuration can be enabled by adding @EnableAutoConfiguration annotation to your main Spring Boot application entry point class.

Git commit id

Git repository information can be injected into a Maven-built Spring Boot-based application. The exact git commit id will be exposed through the /info actuator endpoint.

To do this, we will use maven-git-commit-id-plugin.

<plugin>

    <groupId>pl.project13.maven</groupId>

    <artifactId>git-commit-id-plugin</artifactId>

    <version>2.2.3</version>

</plugin>

Profiles

When writing a library for usage, it’s usually the case that there are different environments in which it may run. With Spring’s profiles, it’s easy to define different configurations that only get active when a certain environment or use case needs them.

We can specify active profiles in application.properties then replace them using the command line switch. We can also have profile-specific properties that add to the active profiles rather than replace them.

Read more about profiles here.

Conclusion

There’s the entire community of people using Spring and contributing to it. If you want to know how to build Spring Boot based project, take a look at spring-boot examples.

Discussion