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!