diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java index f86ffade84..103597ab73 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.data.neo4j; +import org.neo4j.ogm.config.AutoIndexMode; import org.neo4j.ogm.config.Configuration; import org.neo4j.ogm.config.Configuration.Builder; @@ -31,6 +32,7 @@ import org.springframework.util.ClassUtils; * @author Stephane Nicoll * @author Michael Hunger * @author Vince Bickers + * @author Aurélien Leboulanger * @since 1.4.0 */ @ConfigurationProperties(prefix = "spring.data.neo4j") @@ -59,6 +61,11 @@ public class Neo4jProperties implements ApplicationContextAware { */ private String password; + /** + * Auto index mode. + */ + private AutoIndexMode autoIndex = AutoIndexMode.NONE; + private final Embedded embedded = new Embedded(); private ClassLoader classLoader = Neo4jProperties.class.getClassLoader(); @@ -87,6 +94,14 @@ public class Neo4jProperties implements ApplicationContextAware { this.password = password; } + public AutoIndexMode getAutoIndex() { + return this.autoIndex; + } + + public void setAutoIndex(AutoIndexMode autoIndex) { + this.autoIndex = autoIndex; + } + public Embedded getEmbedded() { return this.embedded; } @@ -116,6 +131,7 @@ public class Neo4jProperties implements ApplicationContextAware { if (this.username != null && this.password != null) { builder.credentials(this.username, this.password); } + builder.autoIndex(this.getAutoIndex().getName()); } private void configureUriWithDefaults(Builder builder) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java index e4748ca65e..2fc24742bc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java @@ -22,6 +22,7 @@ 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; @@ -106,6 +107,20 @@ public class Neo4jPropertiesTests { assertCredentials(configuration, "user", "secret"); } + @Test + public void autoIndexNoneByDefault() { + Neo4jProperties properties = load(true); + Configuration configuration = properties.createConfiguration(); + assertThat(configuration.getAutoIndex()).isEqualTo(AutoIndexMode.NONE); + } + + @Test + public void autoIndexCanBeConfigured() { + Neo4jProperties properties = load(true, "spring.data.neo4j.auto-index=validate"); + Configuration configuration = properties.createConfiguration(); + assertThat(configuration.getAutoIndex()).isEqualTo(AutoIndexMode.VALIDATE); + } + @Test public void embeddedModeDisabledUseBoltUri() { Neo4jProperties properties = load(true, diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index b985f5096f..591be0d4e4 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -613,6 +613,7 @@ content into your application; rather pick only the properties that you need. spring.data.redis.repositories.enabled=true # Enable Redis repositories. # NEO4J ({sc-spring-boot-autoconfigure}/neo4j/Neo4jProperties.{sc-ext}[Neo4jProperties]) + spring.data.neo4j.auto-index=none # Auto index mode. spring.data.neo4j.embedded.enabled=true # Enable embedded mode if the embedded driver is available. spring.data.neo4j.open-in-view=false # Register OpenSessionInViewInterceptor. Binds a Neo4j Session to the thread for the entire processing of the request. spring.data.neo4j.password= # Login password of the server.