本文介绍了Vaadin 10/11和嵌入式Jetty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Vaadin 8.5.1上开发了中型应用程序.嵌入式Jetty 9.4.8被用作Vaadin Servlet的Servlet容器.在Java代码中,我初始化Jetty实例,创建Vaadin servlet并将其附加到Jetty.在Maven中,我使用"vaadin-maven-plugin",它可以帮助我对文件夹进行正确的设置,包装也可以是"jar". Spring(不是Spring Boot)用于应用程序配置和IoC.

I developed middle-size application on Vaadin 8.5.1. Jetty embedded 9.4.8 was used as Servlet container for Vaadin servlet. In Java code i initialize Jetty instance, create Vaadin servlet and attach it to Jetty. In Maven i use 'vaadin-maven-plugin' which helps me make correct settings to folders, also packaging is 'jar'. The Spring (not Spring Boot) are used for application configuration purposes and IoC.

现在我想将项目迁移到Vaadin 10/11.我尝试了所有生成输出JAR的Vaadin入门包.但是我不知道如何修改这些包以删除Spring Boot并获得一个嵌入了Jetty的简单Maven项目.

Now i want to migrate project to Vaadin 10/11. I was tried all Vaadin Starter Packs which generates output JAR. But didn't understand how can i modify those packs to remove Spring Boot and get a simple Maven project with Jetty embedded.

Vaadin论坛中已问的问题: Vaadin 10 +嵌入式码头

Already asked question in Vaadin forum:Vaadin 10 + Jetty embedded

推荐答案

您必须按以下方式配置Jetty服务器:

You have to configure the Jetty Server as follows:

public class Application {

    public static void main(String... args) throws Exception {
        new Application().run(8080, "/");
    }

    public void run(int port, String contextPath) throws Exception {
        URL webRootLocation = this.getClass().getResource("/META-INF/resources/");
        URI webRootUri = webRootLocation.toURI();

        WebAppContext context = new WebAppContext();
        context.setBaseResource(Resource.newResource(webRootUri));
        context.setContextPath(contextPath);
        context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*");
        context.setConfigurationDiscovered(true);
        context.setConfigurations(new Configuration[]{
                new AnnotationConfiguration(),
                new WebInfConfiguration(),
                new WebXmlConfiguration(),
                new MetaInfConfiguration(),
                new FragmentConfiguration(),
                new EnvConfiguration(),
                new PlusConfiguration(),
                new JettyWebXmlConfiguration()
        });
        context.getServletContext().setExtendedListenerTypes(true);
        context.addEventListener(new ServletContextListeners());

        Server server = new Server(port);
        server.setHandler(context);

        server.start();
        server.join();
    }

}

此外,如果要将工件打包为uber-jar,则需要使用maven-shade-plugin.

Also, you need to use the maven-shade-plugin if you want to package the artifact as an uber-jar.

您可以在 https://github.com上找到Vaadin 12+的示例. /alejandro-du/embedded-jetty-demo

这篇关于Vaadin 10/11和嵌入式Jetty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 15:36