Thanks Jan, that is really a quick response.
So here is my detailed problem statement:
Technology stack for ACL (our application): Maven, Jetty and Jersey JAX-RS (for RESTful webservices),Spring 3.0
The ACL exposes a REST API and it is implemented using Jersey JAX-RS. To make code testable we wanted introduce IoC so we decided to use spring, and there is spring integration also available for Jersey.
On mvn clean install jetty:run, we are able to post the request to the exposed RESTful API.And it is working all fine.
But issue starts here: We have functional tests written in Cucumber for ACL service.
So we wanted to start the Jetty programmatically (by embedding Jetty). For this purpose we have created the executable jar for ACL(which has all dependencies). The main class, loads the webcontext and starts jetty as below.
ServletHolder sh = new ServletHolder(new ServletContainer(new PackagesResourceConfig("com.delta.api.resources")));
server = new Server(8080);
ServletContextHandler sch = new ServletContextHandler(server, "/");
sch.addServlet(sh, "/*");
server.start();
server.join();
It was working smooth until we introduced spring. For spring to work we modified above code as:
sch.getInitParams().put("contextConfigLocation", "classpath:applicationContext.xml");
sch.addEventListener(new ContextLoaderListener());
After incorporating this, it started loading the spring's application context. But it was loading it after the servlet instantiation ( ServletContextListeners called after servlets are initialized). Hence any method call on autowired objects in servlets started causing NPE.
After googling on it I found out that it is bug in jetty-servlet module and it is fixed in 6.0.2 (JETTY-129 ServletContextListeners called after servlets are initialized - jira.codehaus.org ); but we are using the latest version of jetty-servlet and it much ahead than this one. But still it does not work.
==========================================================================================
The maven dependancies are:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.1.v20120215</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>8.1.1.v20120215</version>
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>jetty</artifactId>
<version>5.1.10</version>
</dependency>
==========================================================================================
web.xml looks like:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<init-param>
<param-name>
com.sun.jersey.config.property.packages
</param-name>
<param-value>com.delta.api.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
==========================================================================================
Leena,
So I can attempt to reproduce this, what's your setup? Are you using jetty embedded or standalone? Do you have any special configuration of your context, or are you just deploying a straight webapp? Are you using any of the servlet 3.0 features such as annotations?
thanks
Jan