Start building against Neo4j OGM 3.0.0 snapshots

This commit our Neo4j OGM dependency with the Spring Data Neo4j
snapshots that are currently included in snapshots of Spring Data Kay.

It switches to using Neo4j's Bolt driver by default, aligning it with
the default of the latest Spring Data Neo4j 5 snapshots.

It also contains a workaround for a Neo4j OGM issue [1] and a change
to Neo4jDataAutoConfigurationTests that prevents the entire classpath
from being scanned.

See gh-8687

[1] https://github.com/neo4j/neo4j-ogm/issues/340
pull/8698/head
Andy Wilkinson 8 years ago
parent b8527d7060
commit 25bf4a14cd

@ -716,6 +716,11 @@
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-http-driver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>

@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.data.neo4j;
import java.util.List;
import org.neo4j.ogm.config.Components;
import org.neo4j.ogm.session.SessionFactory;
import org.neo4j.ogm.session.event.EventListener;
@ -37,8 +38,6 @@ 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.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;
@ -60,13 +59,15 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@ConditionalOnClass({ SessionFactory.class, PlatformTransactionManager.class })
@ConditionalOnMissingBean(SessionFactory.class)
@EnableConfigurationProperties(Neo4jProperties.class)
@SuppressWarnings("deprecation")
public class Neo4jDataAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public org.neo4j.ogm.config.Configuration configuration(Neo4jProperties properties) {
return properties.createConfiguration();
org.neo4j.ogm.config.Configuration configuration = properties
.createConfiguration();
Components.configure(configuration);
return configuration;
}
@Bean
@ -84,12 +85,6 @@ public class Neo4jDataAutoConfiguration {
return sessionFactory;
}
@Bean
@ConditionalOnMissingBean(Neo4jOperations.class)
public Neo4jTemplate neo4jTemplate(SessionFactory sessionFactory) {
return new Neo4jTemplate(sessionFactory);
}
@Bean
@ConditionalOnMissingBean(PlatformTransactionManager.class)
public Neo4jTransactionManager transactionManager(SessionFactory sessionFactory,

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import java.net.URI;
import java.net.URISyntaxException;
import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.config.DriverConfiguration;
import org.springframework.beans.BeansException;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ -43,7 +42,7 @@ public class Neo4jProperties implements ApplicationContextAware {
static final String HTTP_DRIVER = "org.neo4j.ogm.drivers.http.driver.HttpDriver";
static final String DEFAULT_HTTP_URI = "http://localhost:7474";
static final String DEFAULT_BOLT_URI = "bolt://localhost:7687";
static final String BOLT_DRIVER = "org.neo4j.ogm.drivers.bolt.driver.BoltDriver";
@ -62,11 +61,6 @@ public class Neo4jProperties implements ApplicationContextAware {
*/
private String password;
/**
* Compiler to use.
*/
private String compiler;
private final Embedded embedded = new Embedded();
private ClassLoader classLoader = Neo4jProperties.class.getClassLoader();
@ -95,14 +89,6 @@ public class Neo4jProperties implements ApplicationContextAware {
this.password = password;
}
public String getCompiler() {
return this.compiler;
}
public void setCompiler(String compiler) {
this.compiler = compiler;
}
public Embedded getEmbedded() {
return this.embedded;
}
@ -118,29 +104,25 @@ public class Neo4jProperties implements ApplicationContextAware {
*/
public Configuration createConfiguration() {
Configuration configuration = new Configuration();
configureDriver(configuration.driverConfiguration());
if (this.compiler != null) {
configuration.compilerConfiguration().setCompilerClassName(this.compiler);
}
configureDriver(configuration);
return configuration;
}
private void configureDriver(DriverConfiguration driverConfiguration) {
private void configureDriver(Configuration configuration) {
if (this.uri != null) {
configureDriverFromUri(driverConfiguration, this.uri);
configureDriverFromUri(configuration, this.uri);
}
else {
configureDriverWithDefaults(driverConfiguration);
configureDriverWithDefaults(configuration);
}
if (this.username != null && this.password != null) {
driverConfiguration.setCredentials(this.username, this.password);
configuration.setCredentials(this.username, this.password);
}
}
private void configureDriverFromUri(DriverConfiguration driverConfiguration,
String uri) {
driverConfiguration.setDriverClassName(deduceDriverFromUri());
driverConfiguration.setURI(uri);
private void configureDriverFromUri(Configuration configuration, String uri) {
configuration.setDriverClassName(deduceDriverFromUri());
configuration.setURI(uri);
}
private String deduceDriverFromUri() {
@ -165,14 +147,14 @@ public class Neo4jProperties implements ApplicationContextAware {
}
}
private void configureDriverWithDefaults(DriverConfiguration driverConfiguration) {
private void configureDriverWithDefaults(Configuration configuration) {
if (getEmbedded().isEnabled()
&& ClassUtils.isPresent(EMBEDDED_DRIVER, this.classLoader)) {
driverConfiguration.setDriverClassName(EMBEDDED_DRIVER);
configuration.setDriverClassName(EMBEDDED_DRIVER);
return;
}
driverConfiguration.setDriverClassName(HTTP_DRIVER);
driverConfiguration.setURI(DEFAULT_HTTP_URI);
configuration.setDriverClassName(BOLT_DRIVER);
configuration.setURI(DEFAULT_BOLT_URI);
}
public static class Embedded {

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,7 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
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.Neo4jRepository;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.repository.config.Neo4jRepositoryConfigurationExtension;
import org.springframework.data.neo4j.repository.support.Neo4jRepositoryFactoryBean;
@ -35,9 +35,9 @@ import org.springframework.data.neo4j.repository.support.Neo4jRepositoryFactoryB
* Repositories.
* <p>
* 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,
* in the context, the Spring Data Neo4j {@link Neo4jRepository} type is on the classpath,
* the Neo4j client driver API is on the classpath, and there is no other configured
* {@link GraphRepository}.
* {@link Neo4jRepository}.
* <p>
* Once in effect, the auto-configuration is the equivalent of enabling Neo4j repositories
* using the {@link EnableNeo4jRepositories} annotation.
@ -49,7 +49,7 @@ import org.springframework.data.neo4j.repository.support.Neo4jRepositoryFactoryB
* @see EnableNeo4jRepositories
*/
@Configuration
@ConditionalOnClass({ Neo4jSession.class, GraphRepository.class })
@ConditionalOnClass({ Neo4jSession.class, Neo4jRepository.class })
@ConditionalOnMissingBean({ Neo4jRepositoryFactoryBean.class,
Neo4jRepositoryConfigurationExtension.class })
@ConditionalOnProperty(prefix = "spring.data.neo4j.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,8 +17,8 @@
package org.springframework.boot.autoconfigure.data.alt.neo4j;
import org.springframework.boot.autoconfigure.data.neo4j.city.City;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.Neo4jRepository;
public interface CityNeo4jRepository extends GraphRepository<City> {
public interface CityNeo4jRepository extends Neo4jRepository<City, Long> {
}

@ -30,6 +30,8 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.data.neo4j.city.City;
import org.springframework.boot.autoconfigure.data.neo4j.country.Country;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
@ -37,7 +39,6 @@ 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.transaction.Neo4jTransactionManager;
import org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
@ -57,7 +58,6 @@ import static org.mockito.Mockito.verify;
* @author Andy Wilkinson
* @author Kazuki Shimizu
*/
@SuppressWarnings("deprecation")
public class Neo4jDataAutoConfigurationTests {
private ConfigurableApplicationContext context;
@ -75,7 +75,6 @@ public class Neo4jDataAutoConfigurationTests {
assertThat(this.context.getBeansOfType(org.neo4j.ogm.config.Configuration.class))
.hasSize(1);
assertThat(this.context.getBeansOfType(SessionFactory.class)).hasSize(1);
assertThat(this.context.getBeansOfType(Neo4jOperations.class)).hasSize(1);
assertThat(this.context.getBeansOfType(Neo4jTransactionManager.class)).hasSize(1);
assertThat(this.context.getBeansOfType(OpenSessionInViewInterceptor.class))
.hasSize(1);
@ -109,13 +108,6 @@ public class Neo4jDataAutoConfigurationTests {
.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();
@ -154,7 +146,7 @@ public class Neo4jDataAutoConfigurationTests {
if (config != null) {
ctx.register(config);
}
ctx.register(PropertyPlaceholderAutoConfiguration.class,
ctx.register(TestConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
TransactionAutoConfiguration.class, Neo4jDataAutoConfiguration.class);
ctx.refresh();
this.context = ctx;
@ -167,6 +159,12 @@ public class Neo4jDataAutoConfigurationTests {
}
}
@Configuration
@EntityScan(basePackageClasses = Country.class)
static class TestConfiguration {
}
@Configuration
static class CustomSessionFactory {
@ -183,23 +181,12 @@ public class Neo4jDataAutoConfigurationTests {
@Bean
public org.neo4j.ogm.config.Configuration myConfiguration() {
org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration();
configuration.driverConfiguration()
.setDriverClassName(HttpDriver.class.getName());
configuration.setDriverClassName(HttpDriver.class.getName());
return configuration;
}
}
@Configuration
static class CustomNeo4jOperations {
@Bean
public Neo4jOperations myNeo4jOperations() {
return mock(Neo4jOperations.class);
}
}
@Configuration
static class EventListenerConfiguration {

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,9 +22,8 @@ import java.net.URLClassLoader;
import com.hazelcast.util.Base64;
import org.junit.After;
import org.junit.Test;
import org.neo4j.ogm.authentication.Credentials;
import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.config.DriverConfiguration;
import org.neo4j.ogm.config.Credentials;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
@ -56,15 +55,15 @@ public class Neo4jPropertiesTests {
}
@Test
public void defaultUseHttpDriverIfEmbeddedDriverIsNotAvailable() {
public void defaultUseBoltDriverIfEmbeddedDriverIsNotAvailable() {
Neo4jProperties properties = load(false);
Configuration configuration = properties.createConfiguration();
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER,
Neo4jProperties.DEFAULT_HTTP_URI);
assertDriver(configuration, Neo4jProperties.BOLT_DRIVER,
Neo4jProperties.DEFAULT_BOLT_URI);
}
@Test
public void httpUriUseHttpServer() {
public void httpUriUseHttpDriver() {
Neo4jProperties properties = load(true,
"spring.data.neo4j.uri=http://localhost:7474");
Configuration configuration = properties.createConfiguration();
@ -109,12 +108,12 @@ public class Neo4jPropertiesTests {
}
@Test
public void embeddedModeDisabledUseHttpUri() {
public void embeddedModeDisabledUseBoltUri() {
Neo4jProperties properties = load(true,
"spring.data.neo4j.embedded.enabled=false");
Configuration configuration = properties.createConfiguration();
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER,
Neo4jProperties.DEFAULT_HTTP_URI);
assertDriver(configuration, Neo4jProperties.BOLT_DRIVER,
Neo4jProperties.DEFAULT_BOLT_URI);
}
@Test
@ -128,14 +127,13 @@ public class Neo4jPropertiesTests {
private static void assertDriver(Configuration actual, String driver, String uri) {
assertThat(actual).isNotNull();
DriverConfiguration driverConfig = actual.driverConfiguration();
assertThat(driverConfig.getDriverClassName()).isEqualTo(driver);
assertThat(driverConfig.getURI()).isEqualTo(uri);
assertThat(actual.getDriverClassName()).isEqualTo(driver);
assertThat(actual.getURI()).isEqualTo(uri);
}
private static void assertCredentials(Configuration actual, String username,
String password) {
Credentials<?> credentials = actual.driverConfiguration().getCredentials();
Credentials<?> credentials = actual.getCredentials();
if (username == null & password == null) {
assertThat(credentials).isNull();
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,9 +18,9 @@ package org.springframework.boot.autoconfigure.data.neo4j.city;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.Neo4jRepository;
public interface CityRepository extends GraphRepository<City> {
public interface CityRepository extends Neo4jRepository<City, Long> {
@Override
Page<City> findAll(Pageable pageable);

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,8 +16,8 @@
package org.springframework.boot.autoconfigure.data.neo4j.country;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.Neo4jRepository;
public interface CountryRepository extends GraphRepository<Country> {
public interface CountryRepository extends Neo4jRepository<Country, Long> {
}

@ -137,7 +137,7 @@
<mysql.version>5.1.41</mysql.version>
<narayana.version>5.5.3.Final</narayana.version>
<nekohtml.version>1.9.22</nekohtml.version>
<neo4j-ogm.version>2.1.1</neo4j-ogm.version>
<neo4j-ogm.version>3.0.0-SNAPSHOT</neo4j-ogm.version>
<netty.version>4.1.8.Final</netty.version>
<postgresql.version>9.4.1212.jre7</postgresql.version>
<querydsl.version>4.1.4</querydsl.version>
@ -1890,6 +1890,11 @@
<artifactId>neo4j-ogm-api</artifactId>
<version>${neo4j-ogm.version}</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-bolt-driver</artifactId>
<version>${neo4j-ogm.version}</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-compiler</artifactId>
@ -2647,6 +2652,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>
</profile>
<profile>

@ -597,7 +597,6 @@ 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.compiler= # Compiler to use.
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.

@ -689,6 +689,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>
@ -754,6 +761,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>
@ -838,6 +852,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>

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,9 +18,9 @@ package sample.data.neo4j;
import java.util.List;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.Neo4jRepository;
public interface CustomerRepository extends GraphRepository<Customer> {
public interface CustomerRepository extends Neo4jRepository<Customer, Long> {
public Customer findByFirstName(String firstName);

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,10 +16,9 @@
package sample.data.neo4j;
import java.net.ConnectException;
import org.junit.Rule;
import org.junit.Test;
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
import org.springframework.boot.test.rule.OutputCapture;
@ -51,8 +50,7 @@ public class SampleNeo4jApplicationTests {
}
private boolean neo4jServerRunning(Throwable ex) {
System.out.println(ex.getMessage());
if (ex instanceof ConnectException) {
if (ex instanceof ServiceUnavailableException) {
return false;
}
return (ex.getCause() == null || neo4jServerRunning(ex.getCause()));

Loading…
Cancel
Save