Align Spring Data Neo4j auto-configuration with latest Ingalls snapshots

Closes gh-7391
pull/6961/merge
Andy Wilkinson 8 years ago
parent 2ba3b27954
commit af4ca7cf6e

@ -41,6 +41,13 @@
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>neo4j-snapshots</id>
<url>http://m2.neo4j.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>

@ -18,23 +18,26 @@ package org.springframework.boot.autoconfigure.data.neo4j;
import java.util.List;
import org.neo4j.ogm.session.Neo4jSession;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.domain.EntityScanPackages;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.neo4j.template.Neo4jOperations;
import org.springframework.data.neo4j.template.Neo4jTemplate;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data Neo4j.
@ -45,58 +48,67 @@ import org.springframework.data.neo4j.template.Neo4jOperations;
* @author Stephane Nicoll
* @since 1.4.0
*/
@SuppressWarnings("deprecation")
@Configuration
@ConditionalOnClass({ Neo4jSession.class, Neo4jOperations.class })
@ConditionalOnMissingBean(Neo4jOperations.class)
@ConditionalOnClass(SessionFactory.class)
@ConditionalOnMissingBean(SessionFactory.class)
@EnableConfigurationProperties(Neo4jProperties.class)
@SuppressWarnings("deprecation")
public class Neo4jDataAutoConfiguration {
private final Neo4jProperties properties;
public Neo4jDataAutoConfiguration(Neo4jProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public org.neo4j.ogm.config.Configuration configuration() {
return this.properties.createConfiguration();
public org.neo4j.ogm.config.Configuration configuration(Neo4jProperties properties) {
return properties.createConfiguration();
}
@Configuration
static class SpringBootNeo4jConfiguration extends Neo4jConfiguration {
@Bean
public SessionFactory sessionFactory(org.neo4j.ogm.config.Configuration configuration,
ApplicationContext applicationContext) {
return new SessionFactory(configuration, getPackagesToScan(applicationContext));
}
private final ApplicationContext applicationContext;
@Bean
@ConditionalOnMissingBean(Neo4jOperations.class)
public Neo4jTemplate neo4jTemplate(SessionFactory sessionFactory) {
return new Neo4jTemplate(sessionFactory);
}
private final org.neo4j.ogm.config.Configuration configuration;
@Bean
@ConditionalOnMissingBean(PlatformTransactionManager.class)
public Neo4jTransactionManager transactionManager(SessionFactory sessionFactory) {
return new Neo4jTransactionManager(sessionFactory);
}
SpringBootNeo4jConfiguration(ApplicationContext applicationContext,
org.neo4j.ogm.config.Configuration configuration) {
this.applicationContext = applicationContext;
this.configuration = configuration;
private String[] getPackagesToScan(ApplicationContext applicationContext) {
List<String> packages = EntityScanPackages.get(applicationContext)
.getPackageNames();
if (packages.isEmpty() && AutoConfigurationPackages.has(applicationContext)) {
packages = AutoConfigurationPackages.get(applicationContext);
}
return packages.toArray(new String[packages.size()]);
}
@Override
public SessionFactory getSessionFactory() {
return new SessionFactory(this.configuration, getPackagesToScan());
}
@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass({ WebMvcConfigurerAdapter.class,
OpenSessionInViewInterceptor.class })
@ConditionalOnMissingBean(OpenSessionInViewInterceptor.class)
@ConditionalOnProperty(prefix = "spring.data.neo4j", name = "open-in-view", havingValue = "true")
protected static class Neo4jWebConfiguration {
@Configuration
protected static class Neo4jWebMvcConfiguration extends WebMvcConfigurerAdapter {
@Bean
public OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor() {
return new OpenSessionInViewInterceptor();
}
private String[] getPackagesToScan() {
List<String> 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();
}
}

@ -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.
* <p>
* 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}.
* <p>
* 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)

@ -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

@ -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",

@ -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<City> {
}

@ -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();

@ -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);
}
}
}

@ -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;

@ -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<City> {
@Override

@ -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<Country> {
}

@ -133,7 +133,7 @@
<mysql.version>5.1.40</mysql.version>
<narayana.version>5.3.5.Final</narayana.version>
<nekohtml.version>1.9.22</nekohtml.version>
<neo4j-ogm.version>2.0.5</neo4j-ogm.version>
<neo4j-ogm.version>2.1.0-SNAPSHOT</neo4j-ogm.version>
<postgresql.version>9.4.1212.jre7</postgresql.version>
<querydsl.version>4.1.4</querydsl.version>
<reactor.version>2.0.8.RELEASE</reactor.version>
@ -151,7 +151,7 @@
<spring-amqp.version>1.7.0.BUILD-SNAPSHOT</spring-amqp.version>
<spring-cloud-connectors.version>1.2.3.RELEASE</spring-cloud-connectors.version>
<spring-batch.version>3.0.7.RELEASE</spring-batch.version>
<spring-data-releasetrain.version>Ingalls-M1</spring-data-releasetrain.version>
<spring-data-releasetrain.version>Ingalls-BUILD-SNAPSHOT</spring-data-releasetrain.version>
<spring-hateoas.version>0.21.0.RELEASE</spring-hateoas.version>
<spring-integration.version>4.3.5.RELEASE</spring-integration.version>
<spring-integration-java-dsl.version>1.2.0.RELEASE</spring-integration-java-dsl.version>
@ -2594,6 +2594,13 @@
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>neo4j-snapshots</id>
<url>http://m2.neo4j.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>

@ -678,6 +678,13 @@
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>neo4j-snapshots</id>
<url>http://m2.neo4j.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
@ -735,6 +742,13 @@
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>neo4j-snapshots</id>
<url>http://m2.neo4j.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>

Loading…
Cancel
Save