I’m developing an application using Spring and Vaadin across SpringVaadinIntegration add-on, now when i inject the service in my main Vaadin UI class everythings work well, the problem is then i use this annotation in others class.
This is MyService
@Component
@Scope("session")
public class MyService {
public MyService() {
// TODO Auto-generated constructor stub
}
public String getLabel(){
return "this is my label";
}
public void saveUser(Utente utente){
System.out.println("save user");
}
}
This is my main Vaadin UI class
@Component
@Scope("prototype")
public class MyUI extends UI
{
@Autowired
private transient ApplicationContext applicationContext;
@Autowired
private MyService myService;
private MainPanel mainPanel;
private VerticalLayout verticalLayout;
@Override
protected void init(VaadinRequest request) {
// TODO Auto-generated method stub
verticalLayout = new VerticalLayout();
mainPanel = new MainPanel();
verticalLayout.addComponent(mainPanel);
setContent(verticalLayout);
}
}
in MyUI the @autowired work in fact myservice is not null while in Mainpanel doesn’t work
@Component
public class MainPanel extends CustomComponent implements View {
private VerticalLayout mainLayout;
private Button button;
@Autowired
MyService secondService;
public MainPanel() {
buildMainLayout();
setCompositionRoot(mainLayout);
// TODO add user code here
}
@AutoGenerated
private VerticalLayout buildMainLayout() {
// common part: create layout
button = new Button();
mainLayout = new VerticalLayout();
mainLayout.addComponent(button);
button.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
// TODO Auto-generated method stub
secondService.saveUser(new Utente());
}
});
return mainLayout;
}
}
Here where I try to save the user, the service is null. What am I doing wrong?