Skip to content

Commit 06fc95f

Browse files
authored
Fix ScriptUtils.runInitScript() in hierarchical classloader setup by using TCCL (#5167)
1 parent 297621f commit 06fc95f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,13 @@ public static boolean containsSqlScriptDelimiters(String script, String delim) {
293293
*/
294294
public static void runInitScript(DatabaseDelegate databaseDelegate, String initScriptPath) {
295295
try {
296-
URL resource = ScriptUtils.class.getClassLoader().getResource(initScriptPath);
296+
URL resource = Thread.currentThread().getContextClassLoader().getResource(initScriptPath);
297297
if (resource == null) {
298-
LOGGER.warn("Could not load classpath init script: {}", initScriptPath);
299-
throw new ScriptLoadException("Could not load classpath init script: " + initScriptPath + ". Resource not found.");
298+
resource = ScriptUtils.class.getClassLoader().getResource(initScriptPath);
299+
if (resource == null) {
300+
LOGGER.warn("Could not load classpath init script: {}", initScriptPath);
301+
throw new ScriptLoadException("Could not load classpath init script: " + initScriptPath + ". Resource not found.");
302+
}
300303
}
301304
String scripts = IOUtils.toString(resource, StandardCharsets.UTF_8);
302305
executeDatabaseScript(databaseDelegate, initScriptPath, scripts);

0 commit comments

Comments
 (0)