1
我正在開發一個跨SpringVaadinIntegration插件使用Spring和Vaadin的應用程序,現在當我在我的主Vaadin UI類中插入服務時,所有工作都很好,問題出在我身上在其他類使用此批註Vaadin Spring集成插件不起作用
這是爲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");
}
}
這是我的主要Vaadin UI類
@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);
}
}
在MyUI實際上爲MyService的@Autowired工作不在主面板不工作
@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;
}
}
在這裏,我嘗試保存用戶,服務爲空。我究竟做錯了什麼?
嗨。我有同樣的問題。你知道問題是什麼嗎? – RAN
我已經以不同的方式解決了,如果你想要一些建議告訴我怎麼可以聯繫你 – Skizzo
謝謝,但我只是想出瞭如何處理它。 https://vaadin.com/forum#!/thread/1811101 – RAN