Question

I have a servlet that I cannot change (com.sun.jersey.spi.container.servlet.ServletContainer of Jersey RS) . What I can do is create a subclass of it. However, I needed that when the servlet is initialized it runs one function of my subclass. I cannot override the init method because it has the Jersey code.

I tried to use the annotation @PostConstruct on a method to make it run after initialization but it does not work (but it does work under Tomcat 6). In web.xml the class is set to run on startup.

Was it helpful?

Solution

You should be able to subclass ServletContainer, override init, invoke the superclass method then perform your own logic, i.e.

public class MyServletContainer extends ServletContainer {

   public void init() throws ServletException {
      super.init();

      //... perform custom initialization logic here
   }
}

OTHER TIPS

Check if you have some of these jars "commons-annotation.jar, geronimo-annotation_1.1_spec, jboss-annotations-api_1.1_spec" in your webapp lib and remove.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top