I've been thrown into a project that is basically just a REST service an provides some functionality to web clients. 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:
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.
There isn't a "pre-entry" part of JAX-RS per se. However, in any JEE application you can always define a 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. Remember that JAX-RS is still built on top of the servlet framework.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.