不推荐使用 RESTlet 启动初始化? [英] RESTlet startup initialization deprecated?

查看:43
本文介绍了不推荐使用 RESTlet 启动初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 restlet.org 库来构建一个 RESTful Web 界面,我注意到它与对应的 servlet 不同,它没有对 GenericServlet.init() 的补充.

I'm trying to use the restlet.org library to build a RESTful web interface, and I've noticed that unlike it's servlet counterpart, it has no complement to GenericServlet.init().

除了构建另一个 servlet 来执行我的启动逻辑之外,是否有任何内置方法可以避免在第一次请求时构建我的数据库工厂等(以及我必须执行的所有相应锁定以避免多次初始化))?

Short of building another servlet to do my startup logic, is there any built-in way to avoid building my database factories and the like on the first request (and all the commensurate locking I'll have to do to avoid multiple initializations)?

推荐答案

您想在 servlet 容器中运行它吗?如果没有,文档会向您展示如何独立运行它:

Are you wanting to run it in a servlet container? If not, the documentation shows you how to run it stand-alone:

public static void main(String[] args) throws Exception {  
    // Create a new Component.  
    Component component = new Component();  

    // Add a new HTTP server listening on port 8182.  
    component.getServers().add(Protocol.HTTP, 8182);  

    // Attach the sample application.  
    component.getDefaultHost().attach("/firstSteps",  
            new FirstStepsApplication());  

    // Start the component.  
    component.start();
}  

您当然可以在那里进行初始化.

You could certainly do the initialization there.

如果您想使用 servlet 方法,请尝试编写一个新的 servlet 并扩展它们.实现您的 init 方法并为超类调用该方法.

If you want to use the servlet approach, try writing a new servlet and extending theirs. Implement your init method and call the one for the super class.

这篇关于不推荐使用 RESTlet 启动初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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