java - 多个 Spring Boot 应用程序

标签 java spring spring-boot

我正在尝试构建一个包含两个 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/

相关文章:

java - WEB-INF 文件夹中的 web.xml 欢迎文件

java - 在 HTC 长按上使用 TextWatcher 计算字符失败

java - 如何添加自定义列名称Spring Data JPA?

java - Mockito 中的测试服务

java - 通过 REST POST 通过 Java Spring Boot 以流形式接收图像

java - 构造特定的正则表达式

java - 当我启动 Spring 项目时, Controller 方法将被调用三次

java - 通过 Spring Controller 映射图像文件

java - 如何在 Spring boot 1.5.2 中终止 Hibernates 数据库连接?

java - 各种场景下的动静态问题(Java)