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>
  • Loading branch information
HzjNeverStop and 致节 committed Jan 5, 2024
1 parent c394266 commit 11f5507
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</modules>

<properties>
<sofa.ark.version>2.2.6</sofa.ark.version>
<sofa.ark.version>2.2.7-SNAPSHOT</sofa.ark.version>
<project.encoding>UTF-8</project.encoding>
<java.version>1.8</java.version>
<license.maven.plugin>3.0</license.maven.plugin>
Expand Down
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 11f5507

Please sign in to comment.