在springboot应用程序之间共享上下文

时间:2019-08-15 08:30:22

标签: java spring spring-boot

我正在尝试使用一个运行多个端口的进程来创建一个相当奇怪的设置。例如,我希望GET localhost:8080/hello响应world,而GET localhost:8081/hello响应universe

我希望它们是相同的过程,这会使事情稍微复杂一些。

因此,我设法通过创建2个SpringBootApplication类并在类似的单独端口上启动这些类来实现这一目的

fun startWorld() {
    var config = HashMap<String, Any>()
    config.put("server.port", "8080")
    config.put("spring.application.admin.jmx-name", "org.springframework.boot:type=Admin,name=world")
    var app2 = SpringApplication(World ::class.java)
    app2.setDefaultProperties(config)
    app2.run()
}

有趣的部分到了。除了在不同的端口上并提供略有不同的数据外,我还希望它们共享一些服务。 作为示例,我希望:8080/hello应用程序响应:8081/hello被调用多少次。

我尝试使用

创建共享模块
@Component
@Scope("singleton")

类,但似乎未共享spring上下文,因此它不是单例。

这完全有可能吗,如果可以的话,我什至应该看哪里?

0 个答案:

没有答案
相关问题