8

Can I have two (or more) Spring-boot applications running on one Tomcat?

I have two applications packaged as war files and I would like to run them on one Tomcat server. However, when I deploy them, I get the following exception:

org.springframework.jmx.export.UnableToRegisterMBeanException: 
    Unable to register MBean [org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean@2361d8ee] with key 'dumpEndpoint'; 
    nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=dumpEndpoint

The default endpoints that every Spring-boot application registers (like /health etc.) clash. Is there some workaround for this or is not possible to achieve this setup?

Thank you for any responses!

Simulant
  • 19,190
  • 8
  • 63
  • 98
Smajl
  • 7,555
  • 29
  • 108
  • 179

3 Answers3

11

As Spring Boot Reference says:

If your application contains more than one Spring ApplicationContext you may find that names clash. To solve this problem you can set the endpoints.jmx.uniqueNames property to true so that MBean names are always unique.

endpoints.jmx.domain=myapp
endpoints.jmx.uniqueNames=true
Maciej Walkowiak
  • 12,372
  • 59
  • 63
  • Thank you! I missed this one. – Smajl Oct 02 '15 at 07:33
  • 1
    I have two spring boot application deployed on same tomcat and both application have same datasource. I get InstanceAlreadyExistsException: org.apache.tomcat.jdbc.pool.jmx:name=dataSourceMBean,type=ConnectionPool . I have already set endpoints.jmx.domain=myapp endpoints.jmx.uniqueNames=true. But I still get the error. Any suggestions – Mukun Oct 21 '16 at 04:46
  • @Mukun were you able to figure this out? – i_raqz Aug 20 '17 at 05:07
  • I am running multiple spring boot apps in tomcat. But all are connecting to different DB/Schema. – Mukun Aug 21 '17 at 14:40
6

Similar to @Maciej answer. An alternative is to set the following

spring.application.name=my-app-name
spring.jmx.default-domain=my-app-name

Or for application.yaml:

spring:
  application:
    name: my-app-name
  jmx:
    default-domain: my-app-name

Worked for me on Spring boot 1.5.9.RELEASE

DaddyMoe
  • 990
  • 1
  • 14
  • 20
0
spring.jmx.default-domain=app-name
spring.jmx.unique-names=true
4b0
  • 21,981
  • 30
  • 95
  • 142