Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit f59a308

Browse files
committed
Use CLASSIC boot loader
This commit does the following: * Configures the Spring Boot maven plugin to use the legacy CLASSIC boot loader when launching/building uber jars * Simplifies the BootClassLoaderFactory by removing support for legacy Boot 1.3x jar format
1 parent ab68195 commit f59a308

File tree

4 files changed

+24
-44
lines changed

4 files changed

+24
-44
lines changed

spring-cloud-dataflow-build/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@
389389
</execution>
390390
</executions>
391391
<configuration>
392+
<loaderImplementation>CLASSIC</loaderImplementation>
392393
<mainClass>${start-class}</mainClass>
393394
</configuration>
394395
</plugin>

spring-cloud-dataflow-configuration-metadata/src/main/java/org/springframework/cloud/dataflow/configuration/metadata/BootClassLoaderFactory.java

+17-44
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,59 +26,43 @@
2626

2727
/**
2828
* Strategy interface for creating a ClassLoader that mimics the one used when a boot
29-
* uber-jar runs.
29+
* uber jar runs.
3030
*
3131
* @author Eric Bottard
32+
* @author Chris Bono
3233
*/
3334
public class BootClassLoaderFactory {
3435

35-
private static final String BOOT_13_LIBS_LOCATION = "lib/";
36+
private static final String BOOT_LIBS_LOCATION = "BOOT-INF/lib/";
3637

37-
private static final String BOOT_14_LIBS_LOCATION = "BOOT-INF/lib/";
38-
39-
private static final String BOOT_14_CLASSESS_LOCATION = "BOOT-INF/classes/";
38+
private static final String BOOT_CLASSES_LOCATION = "BOOT-INF/classes/";
4039

4140
private final Archive archive;
4241

4342
private final ClassLoader parent;
4443

4544
/**
46-
* Create a new factory for dealing with the given boot uberjar archive.
45+
* Create a new factory for dealing with the given boot uber archive.
4746
*
48-
* @param archive a boot uberjar Archive
49-
* @param parent the parent classloader to set for new created ClassLoaders
47+
* @param archive a boot uber archive
48+
* @param parent the parent classloader to set for created classloader
5049
*/
5150
public BootClassLoaderFactory(Archive archive, ClassLoader parent) {
5251
this.archive = archive;
5352
this.parent = parent;
5453
}
5554

5655
public URLClassLoader createClassLoader() {
57-
boolean useBoot14Layout = false;
58-
for (Archive.Entry entry : archive) {
59-
if (entry.getName().startsWith(BOOT_14_LIBS_LOCATION)) {
60-
useBoot14Layout = true;
61-
break;
62-
}
63-
}
64-
65-
ClassLoaderExposingLauncher launcher = useBoot14Layout ? new Boot14ClassLoaderExposingLauncher()
66-
: new Boot13ClassLoaderExposingLauncher();
67-
68-
return launcher.createClassLoader();
56+
return new ClassLoaderExposingLauncher().createClassLoader();
6957
}
7058

71-
private abstract class ClassLoaderExposingLauncher extends ExecutableArchiveLauncher {
59+
private class ClassLoaderExposingLauncher extends ExecutableArchiveLauncher {
60+
7261
ClassLoaderExposingLauncher() {
7362
super(archive);
7463
}
7564

76-
@Override
77-
protected ClassLoader createClassLoader(URL[] urls) throws Exception {
78-
return new LaunchedURLClassLoader(urls, parent);
79-
}
80-
81-
public URLClassLoader createClassLoader() {
65+
URLClassLoader createClassLoader() {
8266
try {
8367
return (URLClassLoader) createClassLoader(getClassPathArchivesIterator());
8468
}
@@ -87,30 +71,19 @@ public URLClassLoader createClassLoader() {
8771
}
8872
}
8973

90-
}
91-
92-
private class Boot13ClassLoaderExposingLauncher extends ClassLoaderExposingLauncher {
93-
94-
@Override
95-
protected boolean isNestedArchive(Archive.Entry entry) {
96-
return !entry.isDirectory() && entry.getName().startsWith(BOOT_13_LIBS_LOCATION);
97-
}
98-
9974
@Override
100-
protected void postProcessClassPathArchives(List<Archive> archives) throws Exception {
101-
archives.add(0, getArchive());
75+
protected ClassLoader createClassLoader(URL[] urls) {
76+
return new LaunchedURLClassLoader(urls, parent);
10277
}
103-
}
10478

105-
private class Boot14ClassLoaderExposingLauncher extends ClassLoaderExposingLauncher {
10679
@Override
10780
protected boolean isNestedArchive(Archive.Entry entry) {
108-
return (!entry.isDirectory() && entry.getName().startsWith(BOOT_14_LIBS_LOCATION))
109-
|| (entry.isDirectory() && entry.getName().equals(BOOT_14_CLASSESS_LOCATION));
81+
return (!entry.isDirectory() && entry.getName().startsWith(BOOT_LIBS_LOCATION))
82+
|| (entry.isDirectory() && entry.getName().equals(BOOT_CLASSES_LOCATION));
11083
}
11184

11285
@Override
113-
protected void postProcessClassPathArchives(List<Archive> archives) throws Exception {
86+
protected void postProcessClassPathArchives(List<Archive> archives) {
11487
archives.add(0, getArchive());
11588
}
11689
}

spring-cloud-dataflow-parent/pom.xml

+3
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@
329329
<groupId>org.springframework.boot</groupId>
330330
<artifactId>spring-boot-maven-plugin</artifactId>
331331
<version>${spring-boot.version}</version>
332+
<configuration>
333+
<loaderImplementation>CLASSIC</loaderImplementation>
334+
</configuration>
332335
</plugin>
333336
<plugin>
334337
<groupId>org.sonarsource.scanner.maven</groupId>

spring-cloud-skipper/pom.xml

+3
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@
222222
<groupId>org.springframework.boot</groupId>
223223
<artifactId>spring-boot-maven-plugin</artifactId>
224224
<version>${spring-boot.version}</version>
225+
<configuration>
226+
<loaderImplementation>CLASSIC</loaderImplementation>
227+
</configuration>
225228
</plugin>
226229
<plugin>
227230
<groupId>org.sonarsource.scanner.maven</groupId>

0 commit comments

Comments
 (0)