-
Notifications
You must be signed in to change notification settings - Fork 64
Description
环境信息:
boot.version 3.2.12
spring-cloud.version 2023.0.6
spring-cloud-alibaba.version 2023.0.3.3
java.version 17
koupleless.runtime.version 2.1.11
sofa.ark.version 3.1.11
IDEA本地启动,一个基座,一个模块,静态合并部署。
出现异常:
Caused by: java.lang.IllegalArgumentException: Child name [advert] is not unique
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:584)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:571)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:654)
at com.alipay.sofa.ark.springboot.web.ArkTomcatServletWebServerFactory.prepareContext(ArkTomcatServletWebServerFactory.java:220)
at com.alipay.sofa.ark.springboot.web.ArkTomcatServletWebServerFactory.getWebServer(ArkTomcatServletWebServerFactory.java:108)
初步排查:
private final AtomicBoolean deployed = new AtomicBoolean(false);
public void onApplicationEvent(ApplicationContextEvent event) {
if (this.getClass().getClassLoader() == Thread.currentThread().getContextClassLoader()) {
if (ArkConfigs.isEmbedEnable() && ArkConfigs.isEmbedStaticBizEnable() && event instanceof ContextRefreshedEvent && this.deployed.compareAndSet(false, true)) {
EmbedSofaArkBootstrap.deployStaticBizAfterEmbedMasterBizStarted();
}
}
}
此方法会被执行多次,第一次事件是org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.context.annotation.AnnotationConfigApplicationContext@71d9cb05]
第二次事件是org.springframework.context.event.ContextRefreshedEvent[source=FeignClientFactory-iot-saas-device, parent: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@20cfcd3]
尽管存在AtomicBoolean deployed,但是两次事件,是不同的ArkDeployStaticBizListener实例,所以第二次deployed一开始仍然是false,所以相同模块又被再次启动,最终出现异常。