java - 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。
现在我想将项目迁移到 Vaadin 10/11。我尝试了所有生成输出 JAR 的 Vaadin Starter Packs。但不明白如何修改这些包以删除 Spring Boot 并获得一个嵌入 Jetty 的简单 Maven 项目。
已在 Vaadin 论坛中提出问题: 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,则需要使用 。
您可以在https://github.com/alejandro-du/embedded-jetty-demo找到 Vaadin 12+ 的示例
推荐阅读
- reactjs - 反应:状态在事件监听器中保持初始值
- python - 在 Altair 中重新创建 pyLDAvis 图表 - 使用空选择过滤数据
- optaplanner - 为什么 Optaplanner 不允许在模拟退火中配置衰减率?
- c# - Random.Range 总是返回相同的值
- javascript - reactjs如何获取url的主机名
- discord - 如何保存用户的角色历史
- javascript - 无法为新创建的 div 设置或创建“className”属性
- python - 是什么导致“检查失败:ret == 0 (11 vs. 0)通过 pthread_create() 创建线程失败。” 在张量流中
- python - python cv2.imshow() 适用于 root,但不适用于 raspberry pi 上的其他用户
- sql - 如何根据postgresql中另一列的最小值和最大值拆分列