Christian
Christian

Reputation: 1411

Multiple Spring Boot Applications

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

Upvotes: 2

Views: 3257

Answers (2)

Castlebin
Castlebin

Reputation: 11

spring.jmx.enabled = false

Use this setting in application.properties will be ok.

Upvotes: 1

Christian
Christian

Reputation: 1411

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

Upvotes: 0

Related Questions