diff --git a/spring-boot/src/test/java/org/springframework/boot/testutil/FilteredClassPathRunner.java b/spring-boot/src/test/java/org/springframework/boot/testutil/FilteredClassPathRunner.java index f5c80bdd97..c89aa161e7 100644 --- a/spring-boot/src/test/java/org/springframework/boot/testutil/FilteredClassPathRunner.java +++ b/spring-boot/src/test/java/org/springframework/boot/testutil/FilteredClassPathRunner.java @@ -64,8 +64,8 @@ public class FilteredClassPathRunner extends BlockJUnit4ClassRunner { private URLClassLoader createTestClassLoader(Class testClass) throws Exception { URLClassLoader classLoader = (URLClassLoader) this.getClass().getClassLoader(); - return new URLClassLoader(filterUrls(extractUrls(classLoader), testClass), - classLoader.getParent()); + return new FilteredClassLoader(filterUrls(extractUrls(classLoader), testClass), + classLoader.getParent(), classLoader); } private URL[] extractUrls(URLClassLoader classLoader) throws Exception { @@ -219,4 +219,23 @@ public class FilteredClassPathRunner extends BlockJUnit4ClassRunner { } + private static final class FilteredClassLoader extends URLClassLoader { + + private final ClassLoader junitLoader; + + FilteredClassLoader(URL[] urls, ClassLoader parent, ClassLoader junitLoader) { + super(urls, parent); + this.junitLoader = junitLoader; + } + + @Override + public Class loadClass(String name) throws ClassNotFoundException { + if (name.startsWith("org.junit")) { + return this.junitLoader.loadClass(name); + } + return super.loadClass(name); + } + + } + }