Vaadin Spring IoC NullpointerException


I’m trying to Autowire a bean named JdbcTemplate but when I use it on the first line, NullPointerException appears.
It’s a new project , so there is only the “clickme” button autamaticaly genereted and 2 lines added.

XML (only one line)

MyConfiguration class


@Configuration @EnableVaadin
public class MyConfiguration {
@Autowired private PGSimpleDataSource dataSource;

@Bean public DiagramService diagramServiceImp() { return new DiagramServiceImpl(); }

@Bean public JdbcTemplate jdbcTemplate() { [u]
return new JdbcTemplate(dataSource)
[/u]; }

@Bean public PGSimpleDataSource getDataSource(){
PGSimpleDataSource dataSource = new PGSimpleDataSource();
dataSource.setUser("dorito"); dataSource.setPassword("barbe");
return dataSource; }


MyUI class

public class MyUI extends UI {
DiagramServiceImpl diagramServic;

@Override protected void init(VaadinRequest vaadinRequest) {
Button button = new Button("Click Me"); button.addClickListener( e -> {
diagramServic.createDiagram(1,3); });


diagramServic.createDiagram() calls a jdbc.update() méthod , this one launch the NullPointerException
I tried to put @Configurable on MyConfiguration and declare all beans by xml. No effect

Can you help?


Is the NullPointerException caused by a null datasource on JdbcTemplate o by null JdbcTemplate inside DiagramServiceImpl?
How is jdbcTemplate autowired inside DiagramServiceImpl?
Can you post the stacktrace?

Have you tried to inject datasource directly on jdbcTemplate() method ( jdcTemplate(PGSimpleDataSource datasource) ) or
use directly getDataSource() instead of the autowired field in the metod body?


Thanks for your time passed to write a response.

Sorry for to be late. Finally the problem was resolved by using Vaadin with SpringBoot. Because I worked with VaadinSpring like here±+Configuring+and+Using+Vaadin+Spring+without+Spring+Boot