Deploying multiple spring boot applications to a single application server

29 December 2015 Andrzej Karczyński

Spring boot is great framework to easily create applications with production-ready features such as metrics, health checks and externalized configuration. You can create stand-alone applications with embedded servlet container or you can deploy application traditionally to application server. Unfortunately spring boot documentation lacks description, how to deploy multiple spring boot applications into one application server.

Generally it is better to run applications in separate instances of application servers. In this deployment model it is easier to manage resources and isolate application failures. But sometimes there are additional business requirements that several applications must run on one application server.

I found two common problems with deploying multiple spring boot applications to one application server:

  • changing name of application.properties file
  • conflicting jmx bean names

Changing name of application.properties file

Spring boot supports changing name of application.properties file by specifying spring.config.name environment property. This works great for one application, but when we deploy multiple applications into one server, the spring config name would change for all of our applications. So instead of specifying environment property we can supply this value in servlet initializer:

When we want to run application in stand-alone mode or from spring-boot maven plugin we can specify this value in environment property or add this to application main method:

Similarly when running unit tests we can use environment property or add this to main test class constructor:

Conflicting JMX bean names

Many libraries publish jmx beans. Jmx bean names must be unique in JVM. When we deploy two spring boot applications into one application server there can be some name clashes. Fortunately there are ways for changing published bean names. For example you can change spring boot actuator jmx domain by specifying endpoints.jmx.domain property.

Tagged with: , , , , , , , , , , , ,

Hire us!

Pretius is a software development company.
We create web applications using: Java, Oracle DB, Oracle Apex, AngularJS.
Contact us to talk about how we can help you with your software project!