Thursday, February 18, 2010

Vaadin-Spring Integration

I remember the time when i was trying to integrate Spring with Struts2 and GWT applications. The problem was rather documenting the integration stuff i tried to remember them and as usual tend to forgot them. So this time have decided to document the Spring integration with Vaadin.

  • web.xml changes
So first we need to add the Spring Context listener to load the bean configuration file.



Add the Spring Servlet to intercept Vaadin requests


  • Spring Servlet
This servlet connects the Spring with Vaadin. The servlet loads the Vaadin Application class and dispatches all the HTTP requests/responses. The Servlet is available in the Simple Application provided by Vaadin Team for Spring integration.
  • Spring bean configuration
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property>name="driverClassName" value="${db.driver}"/>
  <property>name="url" value="${db.url}"/>
  <property>name="username" value="${db.user}"/>
  <property>name="password" value="${db.pass}"/>    

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  <property>name="dataSource" ref="dataSource"/>

<bean id="dao.user" class="com.dhaval.web.vaadin.spring.dao.UserDaoImpl">

<bean id="testApplication" class="com.dhaval.web.vaadin.spring.MyApplication">

testApplication bean id is same as we have given in the web.xml as an init-param to Spring Servlet.
  • Vaadin Main Application class
This is my Vaadin Application class

public class MyApplication extends Application{
    private UserDaoImpl userDao;

    public MyApplication(UserDaoImpl userDao){
        this.userDao = userDao;

    public void init() {
        Window mainWindow = new Window("Simple Vaadin Spring Integration");

        final TextField txtUser = new TextField("Enter username");
        Button btnCheckUser = new Button("Check Username");
        final Label lblCheckMsg = new Label("");

        btnCheckUser.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                boolean result = userDao.hasUser(txtUser.getValue().toString());
                    lblCheckMsg.setValue("Not Available");



The full source code is available at vaadin-spring-integration in download section.


  1. Hi Dhaval, Thank you for posing this article. Need your help ,I am not able to execute this application.What I am missing in below url? or there is any other way to run it?