Vaadin Spring IoC NullpointerException

Hello,

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


[size=4]

[size=2]
@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.setUrl("jdbc:postgresql://localhost:5432/tfe");
dataSource.setUser("dorito"); dataSource.setPassword("barbe");
return dataSource; }
}
[/size]

[/size]



MyUI class


[size=4]
[size=2]
@Theme("valo")
@SpringUI
public class MyUI extends UI {
@Autowired
DiagramServiceImpl diagramServic;

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

}
[/size]
[/size]

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?

Thanks!

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?

Hello,

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
https://vaadin.com/wiki?p_p_id=36&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=row-1&p_p_col_pos=1&p_p_col_count=3&_36_struts_action=%2Fwiki%2Fview&p_r_p_185834411_nodeName=vaadin.com+wiki&p_r_p_185834411_title=IV±+Configuring+and+Using+Vaadin+Spring+without+Spring+Boot