sofastack / sofa-ark

SOFAArk is a light-weight,java based classloader isolation framework.
https://www.sofastack.tech/projects/sofa-boot/sofa-ark-readme/
Apache License 2.0
1.56k stars 497 forks source link

单Tomcat多模块场景下, Spring Management 没有复用 Tomcat #994

Closed leewaiho closed 2 weeks ago

leewaiho commented 1 month ago

Feature description

Describe the feature details with Chinese or English.

Koupleless 基座 和 Koupleless 模块 通过 application.yml 的 management.server.port 指定了相同端口,基座运行正常,然后在基座上安装指定了相同端口的模块时,报端口已被绑定的异常。

Additional notes

Add other notes if necessary.

image

image

image

yuanyuancin commented 1 month ago

可能是因为createWebServer时,management child context没有ArkServiceInjectProcessor,导致com.alipay.sofa.ark.springboot.web.ArkTomcatServletWebServerFactory#embeddedServerService == null,最终走到了普通TomcatServletWebServerFactory的createWebServer逻辑

leewaiho commented 1 month ago

我 debug 进去看了一下 确实是因为没有 arkinject 导致的 embedded 为空, 但目前对这块还不是特别熟悉, 不知道要怎么改

yuanyuancin commented 1 month ago
  1. 可以考虑扩展 web-ark-plugin 的能力,缓存 management context 同 port 时共享 tomcat,目前 EmbededServerService 只缓存 server context tomcat
  2. 介入 ManagementContext refresh 时添加 ArkServiceInjectProcessor 如果比较难找到扩展点的话,可以考虑在 ArkTomcatServletWebServerFactory 对 embeddedServerService 做延迟注入,getWebServer 调用时提前inject ArkClient.getInjectionService().inject(this);