diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/listener/ArkApplicationStartListener.java b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/listener/ArkApplicationStartListener.java index db4f1aaee..13179d689 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/listener/ArkApplicationStartListener.java +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/listener/ArkApplicationStartListener.java @@ -27,7 +27,6 @@ import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.SpringApplicationEvent; -import org.springframework.boot.loader.LaunchedURLClassLoader; import org.springframework.context.ApplicationListener; /** @@ -40,15 +39,32 @@ public class ArkApplicationStartListener implements ApplicationListener SPRING_BOOT_LOADER_CLASS; + private static Class SPRING_BOOT_NEW_LOADER_CLASS; + + static { + try { + SPRING_BOOT_LOADER_CLASS = ApplicationListener.class.getClassLoader().loadClass( + SPRING_BOOT_LOADER); + } catch (Throwable t) { + // ignore + } + try { + SPRING_BOOT_NEW_LOADER_CLASS = ApplicationListener.class.getClassLoader().loadClass( + SPRING_BOOT_NEW_LOADER); + } catch (Throwable t) { + // ignore + } + } @Override public void onApplicationEvent(SpringApplicationEvent event) { try { - if (ArkConfigs.isEmbedEnable() - || LaunchedURLClassLoader.class.isAssignableFrom(this.getClass().getClassLoader() - .getClass())) { + if (isEmbedEnable()) { ArkConfigs.setEmbedEnable(true); startUpArkEmbed(event); return; @@ -67,6 +83,23 @@ public void onApplicationEvent(SpringApplicationEvent event) { } } + private boolean isEmbedEnable() { + if (ArkConfigs.isEmbedEnable()) { + return true; + } + if (SPRING_BOOT_LOADER_CLASS != null + && SPRING_BOOT_LOADER_CLASS.isAssignableFrom(this.getClass().getClassLoader() + .getClass())) { + return true; + } + if (SPRING_BOOT_NEW_LOADER_CLASS != null + && SPRING_BOOT_NEW_LOADER_CLASS.isAssignableFrom(this.getClass().getClassLoader() + .getClass())) { + return true; + } + return false; + } + public void startUpArk(SpringApplicationEvent event) { if (LAUNCH_CLASSLOADER_NAME.equals(this.getClass().getClassLoader().getClass().getName())) { SofaArkBootstrap.launch(event.getArgs());