我已收到沒有添加UIProvider,並且在Vaadin Framework中嘗試依賴注入後沒有「UI」初始化參數錯誤。我用了專用的Vaadin Spring Addon。我還將VaadinServlet更改爲SpringVaadinServlet,但仍然無效。未添加UIProvider,並且彈簧集成後沒有「UI」初始參數Vaadin錯誤
還有就是我的MainView:
@Theme("mytheme")
@SpringUI
@ComponentScan
@Widgetset("net.elenx.MyAppWidgetset")
public class MainView extends UI {
@Autowired
private VerticalLayout template;
@Override
protected void init(VaadinRequest vaadinRequest) {
new AnnotationConfigApplicationContext(SpringConfig.class);
this.setContent(template);
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MainView.class, productionMode = false)
public static class MyUIServlet extends SpringVaadinServlet {
}
}
導航欄
@Configuration
@EnableVaadin
public class NavigationBar {
@Bean
HorizontalLayout navigationBar(Button hamburgerButton, Label elenxLogo) {
System.out.println("Hello from NavigationBar bean!");
HorizontalLayout navbar = new HorizontalLayout();
navbar.setWidth("100%");
navbar.setMargin(true);
navbar.setHeight(50, Sizeable.Unit.PIXELS);
navbar.addComponent(hamburgerButton);
navbar.addComponent(elenxLogo);
navbar.addStyleName("navigation-bar");
return navbar;
}
@Bean
Button hamburgerButton() {
Button hamburgerButton = new Button();
hamburgerButton.addStyleName("hamburger-button");
hamburgerButton.setIcon(VaadinIcons.MENU);
return hamburgerButton;
}
@Bean
Label elenxLogo() {
Label logo = new Label("ElenX");
logo.addStyleName("elenx-logo");
logo.setWidthUndefined();
logo.setEnabled(false);
return logo;
}
}
SpringConfig
@Configuration
@EnableVaadin
@Import(NavigationBar.class)
public class SpringConfig {
//Create whole view of MainView
@Bean
VerticalLayout template(HorizontalLayout navigationBar) {
System.out.println("Hello from template bean!");
VerticalLayout template = new VerticalLayout();
//NavigationBar navigationBar = new NavigationBar();
Sidebar sidebar = new Sidebar();
template.setMargin(false);
template.setSpacing(false);
template.setHeight("100%");
template.addComponent(navigationBar);
template.addComponent(sidebar.getSidebar());
template.setExpandRatio(sidebar.getSidebar(), 1.0f);
return template;
}
}
什麼是錯的代碼?我不知道發生了什麼事。
你是如何運行你的應用程序,彈簧啓動或傳統web應用程序? – Morfic
網絡應用程序,我在tomcat上支持它 – Zeezl
你的'web.xml'中是否配置了一些東西?通過它的外觀,你的spring上下文在啓動時沒有被初始化,或者應用程序沒有被正確配置來使用它。 – Morfic