packages = EntityScanPackages.get(this.applicationContext)
- .getPackageNames();
- if (packages.isEmpty()
- && AutoConfigurationPackages.has(this.applicationContext)) {
- packages = AutoConfigurationPackages.get(this.applicationContext);
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addWebRequestInterceptor(neo4jOpenSessionInViewInterceptor());
}
- return packages.toArray(new String[packages.size()]);
- }
- @Override
- @Bean
- @Scope(scopeName = "${spring.data.neo4j.session.scope:singleton}", proxyMode = ScopedProxyMode.TARGET_CLASS)
- public Session getSession() throws Exception {
- return super.getSession();
}
}
diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfiguration.java
index 3e81a08097..142fff319c 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfiguration.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfiguration.java
@@ -27,24 +27,20 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
-import org.springframework.data.neo4j.repository.config.GraphRepositoryConfigurationExtension;
-import org.springframework.data.neo4j.repository.support.GraphRepositoryFactoryBean;
+import org.springframework.data.neo4j.repository.config.Neo4jRepositoryConfigurationExtension;
+import org.springframework.data.neo4j.repository.support.Neo4jRepositoryFactoryBean;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Neo4j
* Repositories.
*
- * Activates when there is no bean of type
- * {@link org.springframework.data.neo4j.repository.support.GraphRepositoryFactoryBean}
- * configured in the context, the Spring Data Neo4j
- * {@link org.springframework.data.neo4j.repository.GraphRepository} type is on the
- * classpath, the Neo4j client driver API is on the classpath, and there is no other
- * configured {@link org.springframework.data.neo4j.repository.GraphRepository}.
+ * Activates when there is no bean of type {@link Neo4jRepositoryFactoryBean} configured
+ * in the context, the Spring Data Neo4j {@link GraphRepository} type is on the classpath,
+ * the Neo4j client driver API is on the classpath, and there is no other configured
+ * {@link GraphRepository}.
*
* Once in effect, the auto-configuration is the equivalent of enabling Neo4j repositories
- * using the
- * {@link org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories}
- * annotation.
+ * using the {@link EnableNeo4jRepositories} annotation.
*
* @author Dave Syer
* @author Oliver Gierke
@@ -52,11 +48,10 @@ import org.springframework.data.neo4j.repository.support.GraphRepositoryFactoryB
* @since 1.4.0
* @see EnableNeo4jRepositories
*/
-@SuppressWarnings("deprecation")
@Configuration
@ConditionalOnClass({ Neo4jSession.class, GraphRepository.class })
-@ConditionalOnMissingBean({ GraphRepositoryFactoryBean.class,
- GraphRepositoryConfigurationExtension.class })
+@ConditionalOnMissingBean({ Neo4jRepositoryFactoryBean.class,
+ Neo4jRepositoryConfigurationExtension.class })
@ConditionalOnProperty(prefix = "spring.data.neo4j.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
@Import(Neo4jRepositoriesAutoConfigureRegistrar.class)
@AutoConfigureAfter(Neo4jDataAutoConfiguration.class)
diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigureRegistrar.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigureRegistrar.java
index fa2fa8230c..fc3585a381 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigureRegistrar.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigureRegistrar.java
@@ -21,7 +21,7 @@ import java.lang.annotation.Annotation;
import org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
-import org.springframework.data.neo4j.repository.config.GraphRepositoryConfigurationExtension;
+import org.springframework.data.neo4j.repository.config.Neo4jRepositoryConfigurationExtension;
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
/**
@@ -30,7 +30,6 @@ import org.springframework.data.repository.config.RepositoryConfigurationExtensi
*
* @author Michael Hunger
*/
-@SuppressWarnings("deprecation")
class Neo4jRepositoriesAutoConfigureRegistrar
extends AbstractRepositoryConfigurationSourceSupport {
@@ -46,7 +45,7 @@ class Neo4jRepositoriesAutoConfigureRegistrar
@Override
protected RepositoryConfigurationExtension getRepositoryConfigurationExtension() {
- return new GraphRepositoryConfigurationExtension();
+ return new Neo4jRepositoryConfigurationExtension();
}
@EnableNeo4jRepositories
diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
index 933f160f29..a9d4dadb64 100644
--- a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
+++ b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
@@ -84,18 +84,18 @@
"description": "Enable Mongo repositories.",
"defaultValue": true
},
+ {
+ "name": "spring.data.neo4j.open-in-view",
+ "type": "java.lang.Boolean",
+ "description": "Register OpenSessionInViewInterceptor. Binds a Neo4j Session to the thread for the entire processing of the request.",
+ "defaultValue": false
+ },
{
"name": "spring.data.neo4j.repositories.enabled",
"type": "java.lang.Boolean",
"description": "Enable Neo4j repositories.",
"defaultValue": true
},
- {
- "name": "spring.data.neo4j.session.scope",
- "type": "java.lang.String",
- "description": "Scope (lifetime) of the session.",
- "defaultValue": "singleton"
- },
{
"name": "spring.data.redis.repositories.enabled",
"type": "java.lang.Boolean",
diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/neo4j/CityNeo4jRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/neo4j/CityNeo4jRepository.java
index 9c2718fc7c..a4acf364e3 100644
--- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/neo4j/CityNeo4jRepository.java
+++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/neo4j/CityNeo4jRepository.java
@@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.data.alt.neo4j;
import org.springframework.boot.autoconfigure.data.neo4j.city.City;
import org.springframework.data.neo4j.repository.GraphRepository;
-@SuppressWarnings("deprecation")
public interface CityNeo4jRepository extends GraphRepository {
}
diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java
index 3e43d4d519..327fdfe078 100644
--- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java
+++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java
@@ -53,7 +53,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Vince Bickers
* @author Stephane Nicoll
*/
-@SuppressWarnings("deprecation")
public class MixedNeo4jRepositoriesAutoConfigurationTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java
index e27b482ba7..ef7ef26993 100644
--- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java
+++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java
@@ -20,18 +20,21 @@ import org.assertj.core.api.Assertions;
import org.junit.After;
import org.junit.Test;
import org.neo4j.ogm.drivers.http.driver.HttpDriver;
-import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.data.neo4j.city.City;
import org.springframework.boot.test.util.EnvironmentTestUtils;
+import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.template.Neo4jOperations;
+import org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -43,11 +46,12 @@ import static org.mockito.Mockito.mock;
* @author Stephane Nicoll
* @author Michael Hunger
* @author Vince Bickers
+ * @author Andy Wilkinson
*/
@SuppressWarnings("deprecation")
public class Neo4jDataAutoConfigurationTests {
- private AnnotationConfigApplicationContext context;
+ private ConfigurableApplicationContext context;
@After
public void close() {
@@ -59,31 +63,20 @@ public class Neo4jDataAutoConfigurationTests {
@Test
public void defaultConfiguration() {
load(null, "spring.data.neo4j.uri=http://localhost:8989");
- assertThat(this.context.getBeansOfType(Neo4jOperations.class)).hasSize(1);
assertThat(this.context.getBeansOfType(org.neo4j.ogm.config.Configuration.class))
.hasSize(1);
assertThat(this.context.getBeansOfType(SessionFactory.class)).hasSize(1);
- assertThat(this.context.getBeanDefinition("scopedTarget.getSession").getScope())
- .isEqualTo("singleton");
- }
-
- @Test
- public void customScope() {
- load(null, "spring.data.neo4j.uri=http://localhost:8989",
- "spring.data.neo4j.session.scope=prototype");
- assertThat(this.context.getBeanDefinition("scopedTarget.getSession").getScope())
- .isEqualTo("prototype");
+ assertThat(this.context.getBeansOfType(Neo4jOperations.class)).hasSize(1);
+ assertThat(this.context.getBeansOfType(OpenSessionInViewInterceptor.class))
+ .isEmpty();
}
@Test
- public void customNeo4jOperations() {
- load(CustomNeo4jOperations.class);
- assertThat(this.context.getBean(Neo4jOperations.class))
- .isSameAs(this.context.getBean("myNeo4jOperations"));
+ public void customSessionFactory() {
+ load(CustomSessionFactory.class);
assertThat(this.context.getBeansOfType(org.neo4j.ogm.config.Configuration.class))
.hasSize(0);
- assertThat(this.context.getBeansOfType(SessionFactory.class)).hasSize(0);
- assertThat(this.context.getBeansOfType(Session.class)).hasSize(0);
+ assertThat(this.context.getBeansOfType(SessionFactory.class)).hasSize(1);
}
@Test
@@ -91,25 +84,41 @@ public class Neo4jDataAutoConfigurationTests {
load(CustomConfiguration.class);
assertThat(this.context.getBean(org.neo4j.ogm.config.Configuration.class))
.isSameAs(this.context.getBean("myConfiguration"));
- assertThat(this.context.getBeansOfType(Neo4jOperations.class)).hasSize(1);
+ assertThat(this.context.getBeansOfType(SessionFactory.class)).hasSize(1);
assertThat(this.context.getBeansOfType(org.neo4j.ogm.config.Configuration.class))
.hasSize(1);
- assertThat(this.context.getBeansOfType(SessionFactory.class)).hasSize(1);
+ }
+
+ @Test
+ public void customNeo4jOperations() {
+ load(CustomNeo4jOperations.class);
+ assertThat(this.context.getBean(Neo4jOperations.class))
+ .isSameAs(this.context.getBean("myNeo4jOperations"));
}
@Test
public void usesAutoConfigurationPackageToPickUpDomainTypes() {
this.context = new AnnotationConfigApplicationContext();
String cityPackage = City.class.getPackage().getName();
- AutoConfigurationPackages.register(this.context, cityPackage);
- this.context.register(Neo4jDataAutoConfiguration.class);
+ AutoConfigurationPackages.register((BeanDefinitionRegistry) this.context,
+ cityPackage);
+ ((AnnotationConfigApplicationContext) this.context).register(
+ Neo4jDataAutoConfiguration.class,
+ Neo4jRepositoriesAutoConfiguration.class);
this.context.refresh();
assertDomainTypesDiscovered(this.context.getBean(Neo4jMappingContext.class),
City.class);
}
+ @Test
+ public void openSessionInViewInterceptorCanBeEnabled() {
+ load(null, "spring.data.neo4j.open-in-view=true");
+ assertThat(this.context.getBeansOfType(OpenSessionInViewInterceptor.class))
+ .hasSize(1);
+ }
+
private void load(Class> config, String... environment) {
- AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
+ AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
if (config != null) {
ctx.register(config);
@@ -128,11 +137,11 @@ public class Neo4jDataAutoConfigurationTests {
}
@Configuration
- static class CustomNeo4jOperations {
+ static class CustomSessionFactory {
@Bean
- public Neo4jOperations myNeo4jOperations() {
- return mock(Neo4jOperations.class);
+ public SessionFactory customSessionFactory() {
+ return mock(SessionFactory.class);
}
}
@@ -150,4 +159,14 @@ public class Neo4jDataAutoConfigurationTests {
}
+ @Configuration
+ static class CustomNeo4jOperations {
+
+ @Bean
+ public Neo4jOperations myNeo4jOperations() {
+ return mock(Neo4jOperations.class);
+ }
+
+ }
+
}
diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigurationTests.java
index 50b287e58c..878eb48373 100644
--- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigurationTests.java
+++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jRepositoriesAutoConfigurationTests.java
@@ -44,7 +44,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Vince Bickers
* @author Stephane Nicoll
*/
-@SuppressWarnings("deprecation")
public class Neo4jRepositoriesAutoConfigurationTests {
private AnnotationConfigApplicationContext context;
diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/city/CityRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/city/CityRepository.java
index 1851b7798f..051c0622e0 100644
--- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/city/CityRepository.java
+++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/city/CityRepository.java
@@ -20,7 +20,6 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.neo4j.repository.GraphRepository;
-@SuppressWarnings("deprecation")
public interface CityRepository extends GraphRepository {
@Override
diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/country/CountryRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/country/CountryRepository.java
index 12cbeddcec..a3180af6d8 100644
--- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/country/CountryRepository.java
+++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/country/CountryRepository.java
@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.data.neo4j.country;
import org.springframework.data.neo4j.repository.GraphRepository;
-@SuppressWarnings("deprecation")
public interface CountryRepository extends GraphRepository {
}
diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml
index 41f37c17d5..cb6dfbc3aa 100644
--- a/spring-boot-dependencies/pom.xml
+++ b/spring-boot-dependencies/pom.xml
@@ -131,7 +131,7 @@
5.1.40
5.3.5.Final
1.9.22
- 2.0.5
+ 2.1.0-SNAPSHOT
9.4.1212.jre7
4.1.4
3.0.3.RELEASE
@@ -148,7 +148,7 @@
2.0.0.BUILD-SNAPSHOT
1.2.3.RELEASE
3.0.7.RELEASE
- Ingalls-M1
+ Ingalls-BUILD-SNAPSHOT
0.21.0.RELEASE
5.0.0.BUILD-SNAPSHOT
1.2.6.RELEASE
@@ -2507,6 +2507,13 @@
false
+
+ neo4j-snapshots
+ http://m2.neo4j.org/content/repositories/snapshots
+
+ true
+
+
diff --git a/spring-boot-parent/pom.xml b/spring-boot-parent/pom.xml
index 78e0984aae..e66a6dc159 100644
--- a/spring-boot-parent/pom.xml
+++ b/spring-boot-parent/pom.xml
@@ -679,6 +679,13 @@
false
+
+ neo4j-snapshots
+ http://m2.neo4j.org/content/repositories/snapshots
+
+ true
+
+
@@ -744,6 +751,13 @@
false
+
+ neo4j-snapshots
+ http://m2.neo4j.org/content/repositories/snapshots
+
+ true
+
+