Can Spring JdbcTemplate be used with Vaadin?


I’m trying to put together a simple example that uses Vaadin and Spring Boot and utilizes the database through Spring mechanisms.

The Vaadin TableQuery requires a connection pool argument. But Spring handles this behind the scenes. Is there a way to connect these pieces?

Using 7.3.10 and Spring Boot 1.2.1



Short answer: Yes. You just have to fill the dataSources of your vaadin components with the result of your queries. Do you use JPA for your entities? So you can use the JPA container from vaadin:

Thanks Wolfgang. I finally did figure it out by taking the results and putting them into a BeanItemContainer and then setting the data source for the Table to the item container.

I’m looking at non-JPA specific solutions since we have some legacy stuff that uses a home-grown implementation to access the database.


I am struggling for many days with this as well, is there an example which shows a simple application which uses Vaadin, Spring and JDBC working.

I can’t give you a complete example right now but I have some good news for you:

With the utility of this add-on it should be no problem keep your application running. All you need is a correct configured spring application, vaadin with vaadin-spring and you have to fulfill the interfaces of the bean item containiers of you choice.

I’m also struggling with that problem: When deploying my TestCode I’m getting a NPE for the autowired PersonService on that line:

if ( personService.addPerson(person) > 0){ Here’s the UI class:

public class EquipmentDBUI extends UI {

Logger logger = LoggerFactory.getLogger(EquipmentDBUI.class);

  PersonService personService;

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = EquipmentDBUI.class)
public static class Servlet extends VaadinServlet {

protected void init(VaadinRequest request) {

    final VerticalLayout layout = new VerticalLayout();

    Person person = new Person();

    if ( personService.addPerson(person) > 0){"Person saved successfully");

    String t="";
    for(Person p : personService.getAllPerson()){
      t=t+" "+(p.toString());
    layout.addComponent(new Label("Database Content: "+t ));

[/code]This is the PersonService Class:

public class PersonService {

private JdbcTemplate jdbcTemplate;

public int addPerson(Person person){
jdbcTemplate.execute(“DROP TABLE person IF EXISTS”);
jdbcTemplate.execute("CREATE TABLE person( first_name VARCHAR(150), "
+ “last_name VARCHAR(150), age INTEGER, place VARCHAR(100)”);

String sql = "INSERT INTO person(first_name, last_name, age, place) VALUES(?,?,?,?)";
return jdbcTemplate.update(sql, person.getFirstName(),
    person.getLastName(), person.getAge(), person.getPlace());


public List getAllPerson(){
return jdbcTemplate.query(“SELECT * FROM person”, new RowMapper(){

  public Person mapRow(ResultSet rs, int arg1) throws SQLException {
    Person p = new Person();
    return p;


[/code]the Person class:

public class Person {
private String firstName;
private String lastName;
private int age;
private String place;
public String getFirstName() {
return firstName;
public void setFirstName(String firstName) {
this.firstName = firstName;
public String getLastName() {
return lastName;
public void setLastName(String lastName) {
this.lastName = lastName;
public int getAge() {
return age;
public void setAge(int age) {
this.age = age;
public String getPlace() {
return place;
public void setPlace(String place) { = place;

public String toString(){
StringBuilder builder = new StringBuilder();
.append(", “)
.append(”, “)
.append(”, ")

return builder.toString();




and the pom.xml


<?xml version="1.0" encoding="UTF-8"?>



<description>Demo project for Spring Boot</description>

    <relativePath/> <!-- lookup parent from repository -->



org.springframework.boot spring-boot-starter-jdbc



[/code]Would be very nice if someone has got a hint for me.

Regards Chris

Hi Guys,

I am new to Vaadin and was going along well. I then started looking at Spring for Vaadin and went through a month of hell.

I then thought of ditching Vaadin because it ‘it does not play well with other frameworks’ and of course Spring is the standard.

I then went on to just looking at Spring with Maven and another month of hell. I then chatted to a guy at work who has been developing Java applications for 20 yrs and he said Java is always hectic on configuration and he ow just uses Java and JDBC and avoids ORM and Spring.

That said I then was about to go down this track and thought I would give Vaadin a last look because of time invested, thank goodness.

I am now back on track and loving Vaadin and have a great template together using Vaadin, Shiro for security and JDBC and am amazed at how much control you still have by mixing you own scss with the styles scss.

it is all easy again and I am not looking back so my advice is if you don’t have to use it to avoid Spring and ORM/JPA and just keep it simple. When things go wrong you don’t want to be looking at a generic stack trace from a framework that gives you no idea of what is wrong where. The small amount of time you save on typing with a framework like Spring will be cancelled out many times over figuring out what on earth is going wrong and the more complex your project gets the worse it will get, throw Maven depencies in the mix and then it gets really hairy. I think mix Vaadin (which I think is a complexity which is worth it) with spring (which I do not think is worth it) and complexity is now unmanageable, or at least for someone on my level.

My 2 cents


so all the problems must have had sth. to do with my eclipse/tomcat setup. Starting all over with the Vaadin Spring tutorial setup (, adding the Jdbc-template stuff and run it as Spring Boot App made everything working as it should.

Clad you made it work! Both Spring+Vaadin and Java EE (CDI) + Vaadin approaches work pretty well, I wonder what has been the issue with logan’s setup.

I have a spring jdbc template + vaadin turorial on my TODO. If you want to write one, it would be an awesome contribution for the community :wink: