diff --git a/spring-boot-project/spring-boot-autoconfigure/pom.xml b/spring-boot-project/spring-boot-autoconfigure/pom.xml
index 87981c1ef6..6fe3ae319e 100755
--- a/spring-boot-project/spring-boot-autoconfigure/pom.xml
+++ b/spring-boot-project/spring-boot-autoconfigure/pom.xml
@@ -785,6 +785,11 @@
neo4j-ogm-http-driver
test
+
+ org.neo4j
+ neo4j-ogm-embedded-driver
+ test
+
org.slf4j
log4j-over-slf4j
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java
index 5b3c1dfee9..b4aedf72f5 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java
@@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.data.neo4j;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
+import org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
@@ -30,6 +31,7 @@ import org.springframework.boot.autoconfigure.data.neo4j.empty.EmptyMarker;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
+import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
@@ -92,6 +94,7 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
private void load(Class> config, String... environment) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
+ context.setClassLoader(new FilteredClassLoader(EmbeddedDriver.class));
TestPropertyValues.of(environment)
.and("spring.datasource.initialization-mode=never").applyTo(context);
context.register(config);
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java
index bba4cc5b4c..44ac066639 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java
@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.data.neo4j;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.junit.Test;
+import org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
import org.neo4j.ogm.session.event.Event;
@@ -63,6 +64,7 @@ import static org.mockito.Mockito.verify;
public class Neo4jDataAutoConfigurationTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
+ .withClassLoader(new FilteredClassLoader(EmbeddedDriver.class))
.withUserConfiguration(TestConfiguration.class)
.withConfiguration(AutoConfigurations.of(Neo4jDataAutoConfiguration.class,
TransactionAutoConfiguration.class));
@@ -120,6 +122,7 @@ public class Neo4jDataAutoConfigurationTests {
@Test
public void usesAutoConfigurationPackageToPickUpDomainTypes() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
+ context.setClassLoader(new FilteredClassLoader(EmbeddedDriver.class));
String cityPackage = City.class.getPackage().getName();
AutoConfigurationPackages.register(context, cityPackage);
context.register(Neo4jDataAutoConfiguration.class,
@@ -170,6 +173,7 @@ public class Neo4jDataAutoConfigurationTests {
@Test
public void providesASingletonScopedBookmarkManagerIfNecessaryAndPossible() {
new ApplicationContextRunner()
+ .withClassLoader(new FilteredClassLoader(EmbeddedDriver.class))
.withUserConfiguration(TestConfiguration.class,
BookmarkManagementEnabledConfiguration.class)
.withConfiguration(AutoConfigurations.of(Neo4jDataAutoConfiguration.class,
@@ -183,7 +187,9 @@ public class Neo4jDataAutoConfigurationTests {
@Test
public void doesNotProvideABookmarkManagerIfNotPossible() {
- this.contextRunner.withClassLoader(new FilteredClassLoader(Caffeine.class))
+ this.contextRunner
+ .withClassLoader(
+ new FilteredClassLoader(Caffeine.class, EmbeddedDriver.class))
.withUserConfiguration(BookmarkManagementEnabledConfiguration.class)
.run((context) -> assertThat(context)
.doesNotHaveBean(BookmarkManager.class));
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java
index 9511158f0f..ee6a7d816e 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java
@@ -16,17 +16,16 @@
package org.springframework.boot.autoconfigure.data.neo4j;
-import java.net.URL;
-import java.net.URLClassLoader;
-
import com.hazelcast.util.Base64;
import org.junit.After;
import org.junit.Test;
import org.neo4j.ogm.config.AutoIndexMode;
import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.config.Credentials;
+import org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -174,23 +173,9 @@ public class Neo4jPropertiesTests {
public Neo4jProperties load(boolean embeddedAvailable, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
- ctx.setClassLoader(new URLClassLoader(new URL[0], getClass().getClassLoader()) {
-
- @Override
- protected Class> loadClass(String name, boolean resolve)
- throws ClassNotFoundException {
- if (name.equals(Neo4jProperties.EMBEDDED_DRIVER)) {
- if (embeddedAvailable) {
- return TestEmbeddedDriver.class;
- }
- else {
- throw new ClassNotFoundException();
- }
- }
- return super.loadClass(name, resolve);
- }
-
- });
+ if (!embeddedAvailable) {
+ ctx.setClassLoader(new FilteredClassLoader(EmbeddedDriver.class));
+ }
TestPropertyValues.of(environment).applyTo(ctx);
ctx.register(TestConfiguration.class);
ctx.refresh();
@@ -204,8 +189,4 @@ public class Neo4jPropertiesTests {
}
- private static class TestEmbeddedDriver {
-
- }
-
}