Provides support to increase developer productivity in Java when using the neo4j graph database. Uses familiar Spring concepts such as a template classes for core API usage and provides an annotation based programming model using AspectJ


Spring Data Neo4j

The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services.

The Spring Data Neo4j project aims to provide a familiar and consistent Spring-based programming model for integrating with the Neo4j Graph Database.


  • Automatic mapping of annotated domain entities for nodes and relationships;

  • Powerful CRUD based repositories with provided, derived, and annotated finder methods;

  • Integration with Spring’s comprehensive Transaction management;

  • Agnostic communication with Neo4j through a variety of transport mechanisms (embedded, http, bolt);

  • Integration into Spring Data REST;

  • Seamless integration with Spring Boot.

Documentation & Getting Help

This README is the best place to start learning about the features of Spring Data Neo4j.

To learn more refer to:

If you are new to Spring as well as to Spring Data, look for information about Spring projects.

Quick start

Add the Maven dependency:


      <name>Springframework Maven Milestone Repository</name>

If you’d rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare the appropriate dependency version.


    <!-- used for nightly builds -->
      <name>Springframework Maven SNAPSHOT Repository</name>
You can check out how to get setup with Gradle in the the Reference Manual.

Configure Spring Data Neo4j in your application using JavaConfig bean configuration

@ComponentScan(basePackages = "",...)
@EnableNeo4jRepositories(basePackages = "com.example.person.repository",...)
public class MyConfiguration {

    public SessionFactory sessionFactory() {
        // with domain entity base package(s)
        return new SessionFactory("com.example.person.domain",...);

	public Neo4jTransactionManager transactionManager() {
		return new Neo4jTransactionManager(sessionFactory());

Spring Data Neo4j provides support for connecting to all of Neo4j’s java drivers:

  • Bolt

  • HTTP

  • Embedded

Spring Data Neo4j will attempt to auto-configure itself using a file called, which it expects to find on root of the classpath. Here we will configure the HTTP Driver.


The application can be configured programmatically as well, please consult the reference guide for more information.

Annotate an entity:

public class Person {
    private Long id;
    private String name;

    @Relationship(type = "FRIEND", direction = "OUTGOING")
    private Set<Person> friends;

    public Person() {}
    public Person(String name) { = name; }

    private void knows(Person friend) { friends.add(friend); }

To simplify the creation of data repositories Spring Data Neo4j provides a generic repository programming model. It will automatically create a repository proxy for you that adds implementations of finder methods you specify on an interface.

For example, given the Person class above, a PersonRepository interface that can query for Person by name and when the name matches a like expression is shown below:

public interface PersonRepository extends Neo4jRepository<Person> {

  List<Person> findByName(String name);

  List<Person> findByNameLike(String name);

The queries issued on execution will be derived from the method name.

Typically you will want to call your domain objects and repositories from services. In this Service we find the repository interface and register a proxy object in the container:

public class MyService {

    private final PersonRepository repository;

    public void doWork() {

        Person jon = new Person("Jon");
        Person emil = new Person("Emil");
        Person rod = new Person("Rod");


        // Persist entities and relationships to graph database;

        for (Person friend : emil.getFriends()) {
            System.out.println("Friend: " + friend);

        // Control loading depth
        Person thatSamejon = personRepository.findOne(id, 2);
        for (Person friend : jon.getFriends()) {
            System.out.println("Jon's friends to depth 2: " + friend);

Contributing to Spring Data Neo4j

There are dedicated, mandatory contribution guidelines for all Spring Data projects.

Here are some ways for you to get involved in the community:

  • Get involved with Spring Data Neo4j community on the Neo4j Google Group and by helping on StackOverflow.

  • Create JIRA tickets for bugs and new features and comment and vote on the ones that you are interested in.

  • Github is for social coding: if you want to write code, we encourage contributions through pull requests from a fork of this repository. If you want to contribute code this way, please read the contribution guidelines for details.