在同一个JVM中同时运行2个SpringApplication?

问题描述 投票:0回答:1

我正在运行一些代码作为2个单独的配置,如下所示:

        SpringApplication north = new SpringApplication(MyApp.class);
        north.setAdditionalProfiles("north");
        north.run();

        SpringApplication south = new SpringApplication(MyApp.class);
        south.setAdditionalProfiles("south");
        south.run()

这很好用。但是,当我尝试在ForkJoinPool上同时运行它们时,作为两个单独的任务,日志记录变得混乱(每个线程的相同日志消息显示2-3次或更多)。

我尝试设置org.springframework.boot.logging.LoggingSystem=none但它没有效果。

是否有记录的方法在同一JVM中同时运行两个SpringBoot配置?

multithreading spring-boot
1个回答
0
投票

通过将应用程序的多线程部分从CommandLineRunner::run / SpringApplication::run移动到Bean来解决问题。将SpringApplication::run删除为仅执行初始化,使用返回的ConfigurableApplicationContext来解析和调用基于Bean的进程。

© www.soinside.com 2019 - 2024. All rights reserved.