0

In upgrading to Neo 3.2.3 (from Neo 2.5), I've had to upgrade my Spring Data dependency. The main reason for me upgrading is to take advantage of Neo's new Bolt protocol. I bumped the versions (using maven pom.xml), and I'm having issues with one change in particular -- how to set up the scaffolding for Sessions and the RemoteServer configuration.

org.springframework.data.neo4j.server.RemoteServer has been removed from the SD4N api, breaking my code and I'm not sure how to get things to compile again. I've tried a number of sources online, with little success. Here's what I've read:

Neo4j 3.0 and spring data

https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#_spring_configuration

https://graphaware.com/neo4j/2016/09/30/upgrading-to-sdn-42.html

None of these resources quite explain how to refactor the Spring Configuration (and its clients) to use whatever thing replaces the RemoteServer Object.

How do I connect to my Neo database with Spring Data Neo4J, given a url, username, and password? . Bonus points for explaining how these interrelate to Sessions and SessionFactorys.

1 Answers1

0

The configuration should look like this:

@Configuration
@EnableNeo4jRepositories(basePackageClasses = UserRepository.class)
@ComponentScan(basePackageClasses = UserService.class)
static class Config {

    @Bean
    public SessionFactory getSessionFactory() {
        return new SessionFactory(configuration(), User.class.getPackage().getName());
    }

    @Bean
    public Neo4jTransactionManager transactionManager() throws Exception {
        return new Neo4jTransactionManager(getSessionFactory());
    }

    @Bean
    public org.neo4j.ogm.config.Configuration configuration() {
        return new org.neo4j.ogm.config.Configuration.Builder()
                .uri("bolt://localhost")
                .credentials("username", "password")
                .build();
    }
}

SessionFactory and Session are described here

Please comment about what's unclear in the docs.

nmervaillie
  • 1,145
  • 8
  • 20
  • Thanks, this helps. So does Spring automatically know to create a [Neo4j driver](http://neo4j.com/docs/api/java-driver/current/), or is that instantiated somewhere else? – alex42johnson Oct 29 '17 at 17:10
  • Yes, driver init is managed by SDN. Just make sure to provide the correct dependencies in your POM. – nmervaillie Oct 30 '17 at 09:43