2015-08-31 196 views
1

我想構建一個包含兩個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 [[email protected]6a48a7f3] with key 'requestMappingEndpoint'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=requestMappingEndpoint

我可以想象,這是因爲這兩個應用程序嘗試使用相同的接口註冊。但我如何區分這一點?

感謝您的幫助

+0

正確,他們衝突。我不認爲你可以像這樣在相同的JVM進程中運行2 *應用程序*。你想要什麼原因?也許有更好的解決方案。 – zapl

+0

我基本上需要通過* RESTful *接口進行通信來測試某些內容的應用程序。 – Christian

+1

你可能有2個獨立的項目使用不同的端口(所以他們可以在1臺機器上運行),或者你可以擺脫第二個應用程序,因爲1個應用程序可以有1個以上的休息控制器,你可以對自己的http:// localhost'如果你喜歡。 – zapl

回答

0

事實證明,這是不容易成爲可能。所以我決定將我的第二個應用程序轉換爲一個單獨的包(與另一個端口)。

現在工作正常。

由於zapl

0

spring.jmx.enabled =假

使用在application.properties此設置都會好的。

相關問題