|
1 | 1 | /* |
2 | | - * Copyright 2015-2022 the original author or authors. |
| 2 | + * Copyright 2015-2023 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
22 | 22 | import java.nio.charset.Charset; |
23 | 23 | import java.text.Normalizer; |
24 | 24 | import java.util.List; |
| 25 | +import java.util.function.Supplier; |
25 | 26 | import java.util.stream.Collectors; |
26 | 27 | import java.util.stream.Stream; |
27 | 28 |
|
28 | 29 | import org.apache.ibatis.io.VFS; |
29 | 30 | import org.springframework.core.io.Resource; |
30 | 31 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
31 | 32 | import org.springframework.core.io.support.ResourcePatternResolver; |
| 33 | +import org.springframework.util.ClassUtils; |
32 | 34 |
|
33 | 35 | /** |
34 | 36 | * @author Hans Westerbeek |
|
38 | 40 | public class SpringBootVFS extends VFS { |
39 | 41 |
|
40 | 42 | private static Charset urlDecodingCharset; |
| 43 | + private static Supplier<ClassLoader> classLoaderSupplier; |
41 | 44 | private final ResourcePatternResolver resourceResolver; |
42 | 45 |
|
43 | 46 | static { |
44 | 47 | setUrlDecodingCharset(Charset.defaultCharset()); |
| 48 | + setClassLoaderSupplier(ClassUtils::getDefaultClassLoader); |
45 | 49 | } |
46 | 50 |
|
47 | 51 | public SpringBootVFS() { |
48 | | - this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader()); |
| 52 | + this.resourceResolver = new PathMatchingResourcePatternResolver(classLoaderSupplier.get()); |
49 | 53 | } |
50 | 54 |
|
51 | 55 | @Override |
@@ -77,6 +81,21 @@ public static void setUrlDecodingCharset(Charset charset) { |
77 | 81 | urlDecodingCharset = charset; |
78 | 82 | } |
79 | 83 |
|
| 84 | + /** |
| 85 | + * Set the supplier for providing {@link ClassLoader} to used. |
| 86 | + * <p> |
| 87 | + * Default is a returned instance from {@link ClassUtils#getDefaultClassLoader()}. |
| 88 | + * </p> |
| 89 | + * |
| 90 | + * @param supplier |
| 91 | + * the supplier for providing {@link ClassLoader} to used |
| 92 | + * |
| 93 | + * @since 3.0.2 |
| 94 | + */ |
| 95 | + public static void setClassLoaderSupplier(Supplier<ClassLoader> supplier) { |
| 96 | + classLoaderSupplier = supplier; |
| 97 | + } |
| 98 | + |
80 | 99 | private static String preserveSubpackageName(final String baseUrlString, final Resource resource, |
81 | 100 | final String rootPath) { |
82 | 101 | try { |
|
0 commit comments