A collection of configuration files with very little documentation enabling you to setup your neo4j/Spring/Eclipse project within minutes...
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


neo4j - Spring - REST - Eclipse - Kickstart!

Ok…setting up a simple neo4j standalone project is pretty straightforward…but quite frequently there are some old fashioned Java-Spring-Dinosaurs trying to create "the perfect Eclipse project" enabling these guys to do everything within their IDE. And then you usually end up in POM-hunting, applicationContext.xml-tuning, web.xml modifications etc. and tudaloo: a few hours have passed until you lean back and finally start focusing on your Java services instead of configuring your project/IDE…

This project is dedicated to all Java-Dinos who want to start coding immediately, simply follow the steps below and you can start coding in about five minutes…time's running now!


  • Eclipse 4.2 (J2EE IDE including Web Tools Platform etc.)
  • Spring IDE Eclipse Plugin 3.2
  • Maven 3.04, somewhere around on my Mac

Application stack (bottom up)

  • neo4j backend
  • Repository layer
  • REST layer
  • client interface

1: Create Spring MVC project

After adding Spring IDE plugin you can setup a new Spring project, chose Spring Template and select Spring MVC project as project type…name the project etc. and you will end up in a new helloNeo-project within your IDE…

Spring MVC project

2: Wire in neo & JAX-RS using pom.xml & Maven magic

Ok, the next step is the most important one - use our pom.xml template as this template contains everything you need in order to wire in neo4j as well as several further dependencies (JAX-RS) as there is nothing worse than starting up your tomcat and tomcat complaining about some missing jersey jars etc.. The pom.xml includes as well several dependencies to useful add-ons (JUnit testing, tomcat launcher etc.) which you might use later on.

The pom.xml is directly within the root of this Git repository, simply download the pom.xml and replace the pom.xml within your project. As I'm not gonna maintain this Git project during the next 50 years you might have to update versions but for 2013/2014 you should be fine using our versions ;-)

After replacing pom run:

mvn eclipse:clean

then run:

mvn eclipse:eclipse -Dwtpversion=2.0

3: Start coding neo…

Ok, now it's your turn…dive into the documentation and create some neo repositories, thanx to Spring Data for Neo you can do sth. like this:

public interface HabitantRepository extends GraphRepository
	@Query("start simpsons=node:__types__(className='Habitant') " +
		   "return simpsons")
	public Page findAllHabitants(Pageable page);

4: Create your business logic & cover with REST layer

Ok the rest is pretty straightforward: use your Java experience and create your powerful businesslogic! This logic might access your repositories, for simplicity we simply access a repository from our REST service layer directly:

public class DummyService
	private HabitantRepository habitantRepository;
	// Allows to insert contextual objects into the class
    UriInfo uriInfo;
    Request request;
    // Return the list of orders for applications with json or xml formats
    public List getHabitants() {
    	Habitant hab = new Habitant();
    	List habitants = CollectionsUtil.asList(habitantRepository.findAllHabitants(null));
    	return habitants;

5: Create applicationContext.xml

Usually this is the most annoying step during project creation…Spring configuration can be a nightmare if you are try to challenge yourself setup the configs on your own. In case you simply wanna "get it to work" use our configs! (you might have to adapt your package structure, search for "jooik" and you will find all positions we are currently refering to our own structure)

Add a file applicationContext.xml into the META-INF directory of your project ( src/main/resources ), either copy from our repository or use the file below:

<?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
	                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
	                           http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
	                           http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd">

	<context:spring-configured />
	<context:annotation-config />
	<context:component-scan base-package="com.jooik.demo" />

	<neo4j:repositories base-package="com.jooik.demo.repositories" />

	<mvc:annotation-driven />

	<bean id="jspViewResolver"
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />

	<!-- Cypher query server... -->
	<bean id="serverWrapper" class="org.neo4j.server.WrappingNeoServerBootstrapper"
		init-method="start" destroy-method="stop">
		<constructor-arg ref="graphDatabaseService" />

	<tx:annotation-driven />

	<beans profile="default">
		<neo4j:config storeDirectory="myneo" />

	<beans profile="prod">
		<neo4j:config graphDatabaseService="graphDatabaseService" />


6: Modify web.xml

Almost done! Finally you have to make your web application accessible to REST calls AND you have to load the Spring context during startup so simply make your web.xml looking like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

	<!-- The definition of the Root Spring Container shared by all Servlets 
		and Filters -->

	<!-- Creates the Spring Container shared by all Servlets and Filters -->

	<!-- Processes application requests -->


		<servlet-name>Jersey REST Service</servlet-name>
		<servlet-name>Jersey REST Service</servlet-name>


7: Enjoy Java coding!

Now you've setup the boiler plate so simply start coding!!!

8: Cool things…

Somewhere we've wired in a jsimione dependency…this is cool stuff and you can ship your project to anybody without forcing him/her to install a tomcat. You can simply checkout our project from the repository and fire up a tomcat container running the whole stack using the following commands:

mvn clean install
java -jar target/dependency/webapp-runner.jar target/*.war

P.S.: and the Neo console of course can be accessed as well thanx to clever dependency configuration! localhost:7474...