Vaadin + Spring Data + Neo4j

Here is a little and simple basic configuration for those who wants to develop application based on Vaadin combined with Neo4j. First you shall download the tools.

1. Eclipse

2. JBoss AS 7.1

3. Install maven plugin for Eclipse

Firstly you need to setup  your eclipse to be able to run JBoss (download and install the Jboss Tools). After the IDE and the server is done then you can go further to setup your project configuration. Please kindly follow the steps below

1. Run Eclipse

2. Create maven project and select maven project and press Next

 

3. Just click next

4. On the filter you type Vaadin. And select for Vaadin-architype-client version 1.6.1. and Press Next

5. Give your project a name and finish

6. Yeah your vaadin maven project is now created

7. Start up the JBoss server from eclipse

8. Try to publish the application to the server. Don’t forget to include the gwt-user.jar

9. Yes it is now the Vaadin project is ready. Then the next is to setup the spring data framework to enable us to communicate with the application

10.  Edit your pom.xml and add the below dependencies

</pre>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vaadin.version>6.7.6</vaadin.version>
<gwt.version>2.3.0</gwt.version>
<gwt.plugin.version>2.2.0</gwt.plugin.version>
<spring.version>3.1.0.RELEASE</spring.version>
 </properties>


<dependencies>

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.12</version>
</dependency>

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jsp-api</artifactId>
<version>6.0.35</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin</artifactId>
<version>${vaadin.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>

</dependencies>

11. Edit  and add the following code to Web.xml

</pre>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-spring.xml</param-value>
 </context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
 </listener>

12. Create application context file

13. Add this to the applicationContext-spring.xml

</pre>
<context:spring-configured />
 <context:annotation-config />
 <context:component-scan base-package="spring.TestMinimalist"></context:component-scan>
 <neo4j:config storeDirectory="C:/Users/Rio/Java/Neo4JDatabase2" />
 <neo4j:repositories base-package="spring.TestMinimalist"></neo4j:repositories>
 <bean id="myWindow" class="spring.TestMinimalist.MyWindow" ></bean>
 <tx:annotation-driven mode="aspectj" />

14. Create context helper class for spring.

</pre>
package spring.TestMinimalist;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.ServletContext;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.WebApplicationContext;

public class SpringContextHelper {

private ApplicationContext context;

public SpringContextHelper(Application application) {
 ServletContext servletContext = ((WebApplicationContext) application
 .getContext()).getHttpSession().getServletContext();
 context = WebApplicationContextUtils
 .getRequiredWebApplicationContext(servletContext);
 }

public Object getBean(final String beanRef) {
 return context.getBean(beanRef);
 }

}

15. Now edit your vaadin file application file

</pre>
package spring.TestMinimalist;

import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

@SuppressWarnings("serial")
public class MyVaadinApplication extends Application
{
 private Window window;

@Override
 public void init()
 {
 SpringContextHelper contextHelper = new SpringContextHelper(this);
 MyWindow myWindow = (MyWindow)contextHelper.getBean("myWindow");
 setMainWindow(myWindow);

 }

}
<pre>

15. Here is the full directory list of my project

That is all the configuration needed, After all the setting required then you can publish to your web server to play on. To access the database i will explain it on the different post. you can find my full directory of my project on this link http://goo.gl/ntUen

3 comments

  1. Hi,

    I have been looking for a way to combine this three vaadin + neo4j + spring, so thanks a lot, i’m really and impatiently waiting for the folow up post on database acces on neo4j with an exemple minimalist app

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s