我在 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。
现在我想将项目迁移到 Vaadin 10/11。我尝试了所有生成输出 JAR 的 Vaadin Starter Pack。但不明白如何修改这些包以删除 Spring Boot 并获得嵌入 Jetty 的简单 Maven 项目。
已经在 Vaadin 论坛中提出了问题:Vaadin 10 + Jetty 嵌入 https://vaadin.com/forum/thread/17266527/vaadin-10-jetty-embedded
您必须按如下方式配置 Jetty 服务器:
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();
}
}
另外,您需要使用maven-shade-plugin
如果您想将工件打包为 uber-jar。
您可以在以下位置找到 Vaadin 12+ 的示例:https://github.com/alejandro-du/embedded-jetty-demo https://github.com/alejandro-du/embedded-jetty-demo
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)