有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java多个Spring启动应用程序

我正在尝试构建一个包含两个Sprin引导应用程序的测试设置。 这两个应用程序都有一个单独的类

这两款应用看起来都是这样的:(但它们是不同的、独立的类)

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>";
    }

两者都是从

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

当第二个应用程序启动时,我发现错误:

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

我可以想象这是因为两个应用程序都试图使用相同的接口注册。但我该如何区分这一点呢

谢谢你的帮助


共 (2) 个答案

  1. # 1 楼答案

    春天。jmx。enabled=false

    在应用程序中使用此设置。酒店可以

  2. # 2 楼答案

    事实证明,这是不容易做到的。所以我决定将我的第二个应用程序移动到一个单独的包中(带有另一个端口)

    现在可以了

    多亏了zapl