Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

My Favorite Features of Spring Boot

DZone's Guide to

My Favorite Features of Spring Boot

What are your favorite features of Spring Boot? Check out this developer's thoughts on the best features of Spring Boot.

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

Spring Boot is a lightweight framework that takes most of the work out of configuring Spring-based applications. It follows the “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 the 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 this 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 the @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 the 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 on 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 the  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 an entire community of people using Spring and contributing to it. If you want to know how to build Spring Boot-based projects, take a look at these spring-boot examples.

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

Topics:
java ,spring boot ,opinion ,features ,autoconfiguration ,profile ,endpoints

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}