[英]How can I bootstrap Jersey REST service server?
I've been thrown into a project that is basically just a REST service an provides some functionality to web clients. 我陷入了一个项目,该项目基本上只是一个REST服务,它为Web客户端提供了一些功能。 However, I can't see any bootstrapping going on yet for the services - like not at all.. 但是,我看不到这些服务正在进行任何引导-根本没有。
In particular I have to setup the file system for the server and its services. 特别是我必须为服务器及其服务设置文件系统。 Therefore I am looking for a way to get control of the web application as the server is booting up and before it is loading the REST resources: 因此,我正在寻找一种在服务器启动时以及加载REST资源之前控制Web应用程序的方法:
import javax.ws.rs.Path;
import com.sun.jersey.spi.resource.Singleton;
@Path("/")
@Singleton
public class EnrichmentResource {
// ...
}
How can I do that? 我怎样才能做到这一点? I can only find such simple examples where a REST Controller gets defined but no bootstrapping examples. 我只能找到这样的简单示例 ,其中定义了REST控制器,但没有引导示例。
There isn't a "pre-entry" part of JAX-RS per se. 本身没有JAX-RS的“输入前”部分。 However, in any JEE application you can always define a WebListener: 但是,在任何JEE应用程序中,您始终可以定义WebListener:
@WebListener
public class MyListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println( "context initialized" );
}
}
The contextInitialized() method will be called before anything is called into your REST services. 在调用REST服务之前,将先调用contextInitialized()方法。 Remember that JAX-RS is still built on top of the servlet framework. 记住,JAX-RS仍然建立在servlet框架之上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.