Managing Spring Boot Apps Locally With Trampoline
Managing Spring Boot Apps Locally With Trampoline
Trampoline is an incredibly useful tool, so let's take it for a spin with some microservices to see what it offers for those.
Join the DZone community and get the full member experience.Join For Free
Learn the Benefits and Principles of Microservices Architecture for the Enterprise
Today, I came across an interesting solution for managing Spring Boot applications locally – Trampoline. It is a rather simple product that provides a web console allowing you to start, stop, and monitor your application. It can also sometimes be useful 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 a
java -jar command after building the project with
mvn clean install. By default, the web console is available on port 8080, but you can easily override it with the
server.port parameter. It allows you to:
- Start your application: You can do that by running the Maven Spring Boot plugin command
mvn spring-boot:runthat builds the binary from source code and runs a Java application.
- Shut down your application: You can do that by calling the Spring Boot Actuator
/shutdownendpoint, which performs a graceful shutdown of your application
- Monitor your application: You can have it display some basic information retrieved from Spring Boot Actuator endpoints like traces, logs, metrics, and Git commit data.
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 the Maven command
mvn spring-boot:run. And that is all. Trampoline is available under the 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 the 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 the endpoint
/shutdown is enabled. All changes should be performed 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 the last commit, you should include the Maven plugin
git-commit-id-plugin, which is executed during the application build. Of course, you also need to add the
spring-boot-maven-plugin plugin, which is used for building and running Spring Boot applications from Maven. All the required changes are available in the 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 the Trampoline web console. First, go to the section SETTINGS. You need to register every single instance of your microservices. You can register a(n):
- External, already running application by providing an 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 my microservices by myself, so I’m selecting the third choice. Inside the Register Microservice form, we have to set the microservice name, port, actuator endpoint context path, default build tool, and Maven
pom.xml file location.
It is important to remember setting the 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 a 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 instances 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 your selected port.
The list of running microservices is available below. You can see the application’s HTTP port and status. You may also display traces, logs, or metrics by clicking on one of icons available in every row.
Here’s information about the last commit for
If you decide to restart an application, Trampoline sends the request to the
/shutdown endpoint, rebuilds your application with the newest version of your code, and runs it again. Alternatively, you may use Spring Boot Devtools (by including the 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.
Published at DZone with permission of Piotr Mińkowski , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.