从类路径加载的servlet上下文的热部署? [英] Hot Deployment of servlet contexts loaded from classpath?

查看:155
本文介绍了从类路径加载的servlet上下文的热部署?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下嵌入式Jetty设置:

I've got the following embedded Jetty setup:

    ServletContextHandler topHandler = new ServletContextHandler(server, contextPath);

    // Set path of static resources
    topHandler.setBaseResource(...);

    // Bind dynamic content to /api
    RootResource rootResource = new RootResource();
    FilterHolder restApiHandler = new FilterHolder(rootResource);
    for (Entry<String, String> parameter : initParams.entrySet())
        restApiHandler.setInitParameter(parameter.getKey(), parameter.getValue());
    topHandler.addFilter(restApiHandler, "/api/*", EnumSet.allOf(DispatcherType.class));

    // Bind static content to /
    ServletHolder staticResourceHandler = topHandler.addServlet(DefaultServlet.class, "/");

    server.start();

我在 https上找到了有关热部署的文档. ://www.eclipse.org/jetty/documentation/9.4.19.v20190610/hot-deployment.html ,但我不知道如何将它们放在一起.

And I found documentation on Hot Deployment at https://www.eclipse.org/jetty/documentation/9.4.19.v20190610/hot-deployment.html but I don't understand how to put these together.

在重新加载servlet的类文件后,如何让Jetty重新加载servlet,这样我在开发过程中每次修改Java文件时都不必重新启动服务器?

How do I get Jetty to reload servlets after their class files are reloaded so I don't have to restart the server every time I modify a Java file during development?

推荐答案

热部署通常是WebAppContext的功能之一,WAR概念提供了隔离的ClassLoader.

Hot Deployment is typically a feature of a WebAppContext and the WAR concept that provides isolated ClassLoaders.

ServletContextHandler需要一个自定义的ClassLoader来模仿WebAppContext提供的隔离的类加载器行为.

The ServletContextHandler would need a custom ClassLoader to mimic the isolated classloader behaviors that the WebAppContext provides.

热部署是DeploymentManager和关联的AppProvider的一项功能,该功能可以进行扫描以检测更改(例如在文件系统上).

Hot Deployment is a feature of the DeploymentManager and an associated AppProvider that does the scanning to detect changes (like on a file system).

您需要在Server上将DeploymentManager作为bean.

You'll want a DeploymentManager as a bean on your Server.

您将需要选择一个AppProvider(例如WebAppProvider)来监视目录中的更改,并触发新的App更新回到DeploymentManager.

And you'll want to select a AppProvider (such as WebAppProvider) to monitor a directory for changes and trigger new App updates back to the DeploymentManager.

接下来,您需要在受监视的目录中完全以XML可部署格式声明ServletContextHandler.

Next, you'll want to have your ServletContextHandler declared entirely in the XML deployable format in that monitored directory.

您要修改的类需要来自服务器ClassLoader的ISN以外的地方.

The classes you are modifying need to come from somewhere that ISN'T part of the Server ClassLoader.

您正在使用的XML可部署组件将需要创建此隔离的自定义类加载器,并从该新的(非服务器)位置加载类.

The XML deployable you are using will need to create this isolated custom classloader and load the classes from this new (non-server) location.

这些结合在一起就是您要进行热部署的目标.

These combined are what you are looking at for Hot Deployment.

这篇关于从类路径加载的servlet上下文的热部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆