2

I am trying to build a test setup containing two Sprin Boot Applications. Both of the Apps have a seperate class.

Both Apps look something like this: (but are different, seperated classes)

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;

@RestController
@EnableAutoConfiguration
public class MySpringBootApplet {

    @RequestMapping("/")
    public String home() {
        System.out.println("home() called ..");

        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }

        System.out.println("waited ..");

        return "<!DOCTYPE html><html><body><h1>Test</h1><p>Hello world!</p></body></html>";
    }

Both are started with

SpringApplication app = new SpringApplication(MySpringBootApplet.class);
app.run();

When the second app is started, I get the error:

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

I can imagine that this is because both applications try to register with the same interface. But how do I separate this?

Thanks for your help

Christian
  • 1,341
  • 1
  • 16
  • 35
  • Correct, they clash. And I don't think you can run 2 *applications* in the same JVM process like that. What's the reason you want to? Maybe there is a better solution. – zapl Aug 31 '15 at 12:43
  • I basically need to applications that communicate via a *RESTful* interface to test something. – Christian Aug 31 '15 at 12:46
  • 1
    You could have 2 separate projects using different ports (so they can run on 1 machine) or you could get rid of the 2nd application because 1 app can have more than 1 rest controller and you can `http://localhost` to yourself if you like. – zapl Aug 31 '15 at 12:54
  • The **reason** and **solutions** can be found in the related posts: [here](https://stackoverflow.com/questions/34987502/while-deploying-more-than-one-spring-boot-application-in-a-single-tomcat-server) and [here](https://stackoverflow.com/questions/32901936/multiple-spring-boot-applications-running-on-one-tomcat). – informatik01 May 11 '20 at 19:25

2 Answers2

1

spring.jmx.enabled = false

Use this setting in application.properties will be ok.

Castlebin
  • 11
  • 1
0

It turns out that this is not easily possible. So I decided to move my second App into a separate package (with another port).

It works fine now.

Thanks to zapl

Community
  • 1
  • 1
Christian
  • 1,341
  • 1
  • 16
  • 35