我正在尝试构建一个包含两个 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: 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
我可以想象这是因为两个应用程序都尝试使用相同的接口(interface)注册。但我该如何分开呢?
感谢您的帮助
最佳答案
spring.jmx.enabled = false
在application.properties中使用这个设置就可以了。
关于java - 多个 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32311298/