Vaadin and Spring injector
We will make a simple application that shows the username on the screen. Our goal in the recipe is to auto inject or maybe (in better terms) autowire Spring beans in the Vaadin application.
Getting ready
Create new Maven project from the Vaadin archetype.
mvn archetype:generate \ -DarchetypeGroupId=com.vaadin \ -DarchetypeArtifactId=vaadin-archetype-application \ -DarchetypeVersion=LATEST \ -Dpackaging=war \ -DgroupId=com.packtpub.vaadin \ -DartifactId=vaadin-spring-injector \ -Dversion=1.0
How to do it...
Carry out the following steps, in order to make a Vaadin application with autowiring via injector:
First, we create a class representing a user.
public class User { private String name; // generate getters and setters for name field }
Create a service that returns a new user always when the
getUser()
method is called.public class UserService { public User getUser() { // TODO: here we could fetch data from e.g. database User user = new User(); ...