Skip to content

Commit

Permalink
1. update 2.2.7-SNAPSHOT (#823)
Browse files Browse the repository at this point in the history
2. support SpringBoot 3.2.0 new LaunchedURLClassLoader class

Co-authored-by: 致节 <hzj266771@antgroup.com>

(cherry picked from commit 11f5507)
  • Loading branch information
HzjNeverStop authored and lvjing2 committed Jan 11, 2024
1 parent 15adee2 commit ac415b5
Showing 1 changed file with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -40,15 +39,32 @@ public class ArkApplicationStartListener implements ApplicationListener<SpringAp

private static final String LAUNCH_CLASSLOADER_NAME = "sun.misc.Launcher$AppClassLoader";
private static final String SPRING_BOOT_LOADER = "org.springframework.boot.loader.LaunchedURLClassLoader";
//SpringBoot 3.2.0 support
private static final String SPRING_BOOT_NEW_LOADER = "org.springframework.boot.loader.launch.LaunchedClassLoader";
private static final String APPLICATION_STARTED_EVENT = "org.springframework.boot.context.event.ApplicationStartedEvent";
private static final String APPLICATION_STARTING_EVENT = "org.springframework.boot.context.event.ApplicationStartingEvent";
private static Class<?> 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;
Expand All @@ -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());
Expand Down

0 comments on commit ac415b5

Please # to comment.