Zeezl
Zeezl

Reputation: 133

No UIProvider has been added and there is no "UI" init parameter Vaadin error after Spring integration

I recived No UIProvider has been added and there is no "UI" init parameter error after I tried dependency injection in Vaadin Framework. I used dedicated Vaadin Spring Addon. I also changed VaadinServlet to SpringVaadinServlet, still doesn't work.

There is my 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 {
    }

}

NavigationBar

@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;
    }
}

What is wrong with this code? I have no idea what's going on..

Upvotes: 1

Views: 2263

Answers (1)

mike.goetz
mike.goetz

Reputation: 21

Although this is an old question.

Did you followed the instructions from Spring Boot http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file on how to create a deployable war?

Your Spring Boot Application class needs to extends SpringBootServletInitializer

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure ( SpringApplicationBuilder application ) {
        return application.sources ( Application.class );
    }

    public static void main ( String [] args ) {
        SpringApplication.run ( Application.class, args );
    }
}

You can also checkout the following projects on github.

Spring Boot and Vaadin

Vaadin 7 https://github.com/mike-goetz/spring-boot-vaadin7

Vaadin 8 https://github.com/mike-goetz/spring-boot-vaadin

Upvotes: 2

Related Questions