我正在尝试使用reSTLet.org 库来构建RESTful Web 界面,并且我注意到与Servlet 对应物不同,它没有对GenericServlet.init() 的补充。
缺少构建另一个 servlet 来执行我的启动逻辑,是否有任何内置方法可以避免在第一个请求上构建我的数据库工厂等(以及我必须执行的所有相应锁定以避免多次初始化)?
最佳答案
您想在 servlet 容器中运行它吗?如果没有,文档将向您展示如何独立运行它:
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();
}
您当然可以在那里进行初始化。
如果您想使用 servlet 方法,请尝试编写一个新的 servlet 并扩展它们。实现您的 init 方法并调用父类(super class)的方法。
关于java - RESTlet 启动初始化已弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3010855/