Managing Spring Boot apps locally with Trampoline
Today I came across an interesting solution for managing Spring Boot applications locally – Trampoline. It is rather a simple product, that provides a 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 a 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 the 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:run
that build the binary from source code and run Java application - Shutdown your application – it is realized by calling Spring Boot Actuator
/shutdown
endpoint 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.
Setup
First, you need to clone the Trampoline repository from GitHub. It is available here: https://github.com/ErnestOrt/Trampoline.git. The application is available inside the trampoline
directory. You can run its main class Application
or just run Maven command mvn spring-boot:run
. And that is all. Trampoline is available under address http://localhost:8080.
Configuring applications
We will use one of my previous samples 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 performed in Spring Boot YAML configuration files, which are stored on config-service
.
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 the 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>
Adding microservices
The further configuration will be provided using the Trampoline web console. First, go 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 (config-service
, discovery-service
, gateway-service
, and three Spring Cloud applications) we may add them to one group. It is a very useful feature, because then we could deploy them all with one click.
Here’s the full list of services registered in Trampoline.
Managing microservices
Now, we can navigate to the section INSTANCES. We can launch a single instance of microservices or a group of microservices. If you would like to launch a single instance just select it from the list on the Launch Instance panel and click the button Launch. It immediately starts a new command window, builds your application from source code and launches it under the selected port.
The list of running microservices is available below. You can see their application’s HTTP port and status. You may also display trace, logs or metrics by clicking on one of the icons available at every row.
Here’s information about last commit for discovery-service
.
If you decide to restart an application Trampoline sends a request to /shutdown
endpoint, rebuilds your application with the 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 the status of all registered applications by calling its actuator endpoints you will still see the full list of running microservices.
1 COMMENT