Spring Boot comes with interesting features, one of which is to provide production ready, stand-alone application (embeds web server) with built-in monitoring and debugging facilities out-of-the-box. This enables immutable container deployment units that can help with continuous deployment at scale.
Impressed by the above, I converted a spring mvc based webservice to a spring boot application. Things I did included adding the following dependencies to pom.xml, removing the existing spring-context and spring-webmvc dependencies, changing the packaging to jar from war and providing a starter class that wires up spring boot and spring. Viola – got endpoints that allow me to look at config, url to controller mapping/documentation, take thread dumps, health check, access logs and more, click here for endpoints documentation.
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.3.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> ... <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin>
Starter class looks like this:
@SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
In case, if you want to leverage the monitoring and debugging features for an existing war application, the following maven pom additions are required in addition to retaining packaging to war.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>