Make use of start.spring.io
to bootstrap a new spring project.
Spring Boot helps you build applications quickly with the following features:
- Spring Initializr: Helps with project bootstraping
- Spring Boot Starter Project: Helps you to quickly define dependencies for your projects. They provide Convenient Dependency Descriptors.
- Spring Boot Auto Configuration: Helps with automatically defining configuration based on the dependencies in the class path
- Spring Boot Dev Tools: Make application changes without having to manually restart the server
Spring Boot helps you build Production-Ready code with the following features:
- Logging
- Different configuration profiles for different Environment - Using
spring.profile.active
property - Monitoring
Spring Boot (NOT Spring MVC) provides non functional requirements (NFRs) - Actuator and Embedded Server, Profiles and ConfigurationProperties.
Spring is the Framework, Spring MVC is a module of the framework used for building web applications and APIs and Spring Boot is a Project that makes use of both Spring and Spring MVC with a number of Non-Functional Requirements to help you quickly build Spring applications
Logging Levels
- Trace
- Debug
- Info
- Warining
- Error
- Off
To create configuration profiles for different environments, we for example create application property files with the following names:
- application.properties: The default configuration file used, if no profile is set
- appication-dev.properties: A configuration profile called
dev
in this case - application-prod.properties: A configuration profile called
prod
in this case
To select the profile that the spring application makes use of, set spring.profiles.active=dev
in the application.properties
file to select dev
as the active configuration profile.
Note that what Spring does is to merge the content of the default profile with that of the selected profile. If the same set of fields appear in both profiles, the fields in the selected profile take preceedence over those in the default profile
The Spring Boot feature which helps us monitor and manage our application in production is called Actuator. Some of the monitoring endpoints exposed by Spring Boot Actuators are:
- metrics
- beans
- health
- mappings
Set the following property for example in your application.properties file, to select what metric endpoint to expose:
management.endpoints.web.exposure.include=*
: Exposes all Spring Boot Actuator metrics endpointsmanagement.endpoints.web.exposure.include=health,metrics
: Exposes only the health and metrics endpoints