Integrating Vaadin 7 and Spring

Nov 11, 2012   #java  #vaadin  #spring  #web 

I am currently building an administration interface for TweetsQueue with Vaadin 7. Fortunately Spring integration for Vaadin 7 is available as a Vaadin add-on.

Only two simple steps are necessary to get full autowiring support for your Vaadin classes.

  • Add the Spring integration as a dependency. Here’s the relevant excerpt of my build.gradle: //... repositories { mavenRepo url: 'http://repo1.maven.org/maven2/', artifactUrls: ['http://maven.springframework.org/milestone', 'http://maven.vaadin.com/vaadin-addons'] } dependencies { ... runtime 'ru.xpoft.vaadin:spring-vaadin-integration:1.6.2' ... } ...

  • Define the Spring integration servlet and your main UI bean in your web.xml: contextConfigLocation classpath*:applicationContext*.xml org.springframework.web.context.ContextLoaderListener VaadinServlet ru.xpoft.vaadin.SpringVaadinServlet beanName mainUI VaadinServlet /*

You can now autowire your views (declared as Spring beans) into your main ui class and display them as needed.