I got No qualifying bean of type [com.vaadin.ui.HorizontalLayout] found for dependency error when I try to inject argument from another config file like this: Main Config:
@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;
}
}
Second config:
@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;
}
}
So what's the corrent way of realizing this injection? I want to have Beans for each elements and just inject them to build whole layout. When I tried change this line:
@Bean
VerticalLayout template(HorizontalLayout navigationBar) {
To this:
@Bean
VerticalLayout template(@Qualifier("navigationBar") HorizontalLayout navigationBar) {
I got "Could not autowire. Qualifier bean must of 'Component' type" error. I'm fresh to Spring and I'm not sure what have I done wrong, shouldn't Spring match my HorizontalLayout navigationBar method with the parameter of VerticalLayout template(HorizontalLayout navigationBar)?