簡體   English   中英

多個Spring Boot應用程序

[英]Multiple Spring Boot Applications

我正在嘗試建立一個包含兩個Sprin Boot應用程序的測試設置。 這兩個應用程序都有單獨的類。

這兩個應用程序看起來都像這樣:(但是不同的,單獨的類)

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:無法使用鍵“ requestMappingEndpoint”注冊MBean [org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean@6a48a7f3]; 嵌套的異常是javax.management.InstanceAlreadyExistsException:org.springframework.boot:type = Endpoint,name = requestMappingEndpoint

我可以想象這是因為兩個應用程序都嘗試使用相同的接口注冊。 但是我該如何區分呢?

謝謝你的幫助

事實證明,這不容易實現。 因此,我決定將我的第二個應用程序移動到一個單獨的程序包中(帶有另一個端口)。

現在工作正常。

感謝zapl

spring.jmx.enabled = false

在application.properties中使用此設置就可以了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM