1

在我尝试在 Vaadin Framework 中进行依赖注入后,我收到了 No UIProvider has been added 并且没有“UI”初始化参数错误。我使用了专用的 Vaadin Spring Addon。我也把 VaadinServlet 改成了 SpringVaadinServlet,还是不行。

有我的主视图:

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

这段代码有什么问题?我不知道是怎么回事..

4

1 回答 1

2

虽然这是一个老问题。

您是否按照 Spring Boot http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file关于如何创建可部署战争的说明进行操作?

您的 Spring Boot Application 类需要扩展 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 );
    }
}

您还可以在 github 上查看以下项目。

Spring Boot 和 Vaadin

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

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

于 2016-11-30T20:46:02.977 回答