我刚开始使用Spring Framework。我在Vaadin中写了一小段代码来注入依赖。
的MainView:
@Theme("mytheme")
@SpringUI
@Widgetset("net.elenx.MyAppWidgetset")
public class MainView extends UI {
static {
new AnnotationConfigApplicationContext(SpringConfig.class);
}
@Autowired
private VerticalLayout template;
@Override
protected void init(VaadinRequest vaadinRequest) {
this.setContent(template);
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MainView.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}
SpringConfig
@Configuration
@EnableVaadin
public class SpringConfig {
@Bean
//Create whole view of MainView
public VerticalLayout createView() {
VerticalLayout template = new VerticalLayout();
NavigationBar navigationBar = new NavigationBar();
Sidebar sidebar = new Sidebar();
template.setMargin(false);
template.setSpacing(false);
template.setHeight("100%");
template.addComponent(navigationBar.getNavigationBar());
template.addComponent(sidebar.getSidebar());
template.setExpandRatio(sidebar.getSidebar(), 1.0f);
return template;
}
}
我不确定这段代码是否相同。但问题是我的UI没有加载所以我认为我的Bean没有正确绑定。我没有任何错误甚至警告,应用程序编译和没有问题,任何想法?我错过了什么吗?