Today I came across interesting solution for managing Spring Boot applications locally – Trampoline. It is rather a simple product, that provides web console allowing you to start, stop and monitor your application. However, it can sometimes be useful, especially if you run many different applications locally during microservices development. In this article I’m going to show the main features provided by Trampoline.
How it works
Trampoline is also Spring Boot application, so you can easily start it using your IDE or with
java -jar command after building the project with
mvn clean install. By default web console is available on 8080 port, but you can easily override it with
server.port parameter. It allows you to:
- Start your application – it is realized by running Maven Spring Boot plugin command
mvn spring-boot:runthat build the binary from source code and run Java application
- Shutdown your application – it is realized by calling Spring Boot Actuator
/shutdownendpoint that performs gracefully shutdown of your application
- Monitor your application – it displays some basic information retrieved from Spring Boot Actuator endpoints like trace, logs, metrics and Git commit data.
First, you need to clone Trampoline repository from GitHub. It is available here: https://github.com/ErnestOrt/Trampoline.git. The application is available inside
trampoline directory. You can run its main class
Application or just run Maven command
mvn spring-boot:run. And it is all. Trampoline is available under address http://localhost:8080.
We will use one of my previous sample of microservices built with Spring Boot 2.0. It is available on my GitHub account in repository sample-spring-microservices-new available here: https://github.com/piomin/sample-spring-microservices-new.git. Before deploying these microservices on Trampoline we need to perform some minor changes. First, all the microservices have to expose Spring Boot Actuator endpoints. Be sure that endpoint
/shutdown is enabled. All changes should be perform in Spring Boot YAML configuration files, which are stored on
management: endpoint.shutdown.enabled: true endpoints.web.exposure.include: '*'
If you would like to provide information about last commit you should include Maven plugin
git-commit-id-plugin, which is executed during application build. Of course, you also need to add
spring-boot-maven-plugin plugin, which is used for building and running Spring Boot application from Maven. All the required changes are available in branch trampoline (https://github.com/piomin/sample-spring-microservices-new/tree/trampoline).
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>pl.project13.maven</groupId> <artifactId>git-commit-id-plugin</artifactId> </plugin> </plugins> </build>
The further configuration will be provided using Trampoline web console. First, got to section SETTINGS. You need to register every single instance of your microservices. You can register:
- External, already running application by providing its IP address and HTTP port
- Git repository with your microservice, which then will be cloned into your machine
- Git repository with your microservice existing on the local machine just by providing its location
I have cloned the repository with microservices by myself, so I’m selecting a third choice. Inside Register Microservice form we have to set microservice name, port, actuator endpoint context path, default build tool and Maven
pom.xml file location.
It is important to remember about setting Maven home location in the panel Maven Settings. After registering all sample microservices (
gateway-service, and three Spring Cloud applications) we may add them to one group. It is very useful feature, because then we could deploy them all with one click.
Here’s the full list of services registered in Trampoline.
Now, we can navigate to the section INSTANCES. We can launch single instance of microservices or a group of microservices. If you would like to launch a single instance just select it from list on Launch Instance panel and click button Launch. It immediately starts new command window, builds your application from source code and launches it under selected port.
The list of running microservices is available below. You can see there application’s HTTP port and status. You may also display trace, logs or metrics by clicking on one of icon available at every row.
Here’s an information about last commit for
If you decide to restart an application Trampoline sends request to
/shutdown endpoint, rebuilds your application with newest version of code and runs it again. Alternatively, you may use Spring Boot Devtools (by including dependency
org.springframework.boot:spring-boot-devtools), which forces your application to be restarted after source code modification. Because Trampoline is continuously monitoring status of all registered applications by calling its actuator endpoints you will still see the full list of running microservices.