我得到了沒有符合條件的bean類型的[com.vaadin.ui.HorizontalLayout]找到依賴性錯誤,當我嘗試從另一個配置文件注入參數時,如下所示: Main Config:找不到符合條件的類型的bean,vaadin
@Configuration
@EnableVaadin
@Import(NavigationBar.class)
@ComponentScan("net.elenx")
public class SpringConfig {
//Create whole view of MainView
@Bean
VerticalLayout template(@Qualifier("navigationBar") HorizontalLayout navigationBar) {
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;
}
}
二配置:
@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;
}
}
那麼什麼是實現這一注射corrent方式?我想爲每個元素都有Beans,只是注入它們來構建整個佈局。當我試圖改變這一行:
@Bean
VerticalLayout template(HorizontalLayout navigationBar) {
要這樣:
@Bean
VerticalLayout template(@Qualifier("navigationBar") HorizontalLayout navigationBar) {
我得到「無法自動裝配‘組件’類型的預選賽豆必須的。」的錯誤。我是新鮮的春天,我不知道我做錯了什麼,不應該Spring我的HorizontalLayout navigationBar方法與VerticalLayout模板(HorizontalLayout navigationBar)參數匹配?
好的我明白了,那麼在Vaadin編寫UI模塊(如邊欄,導航欄)的最佳方式是什麼?我關心最好的代碼,謝謝你的回答! – Zeezl
不客氣,我相應地編輯了我的答案。 –