title: SEVERE: Servlet.service() for servlet [abc] in context with path [/xyz] threw exception [java.lang.NullPointerException]
body: <p>Developing rest web service with jersey, maven and spring. New to spring and maven. facing SEVERE: Servlet.service() for servlet [abc] in context with path [/xyz] threw exception [java.lang.NullPointerException] issue. when i invoke rest web service My response object is null.
  Below is my pom.xml</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.ecable&lt;/groupId&gt;
    &lt;artifactId&gt;ecableWS&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
  &lt;properties&gt;
          &lt;jersey.version&gt;2.2&lt;/jersey.version&gt;
          &lt;javax.servlet.version&gt;2.3&lt;/javax.servlet.version&gt;
          &lt;spring.batch.version&gt;2.2.0.RELEASE&lt;/spring.batch.version&gt;
          &lt;spring.version&gt;3.1.1.RELEASE&lt;/spring.version&gt;
          &lt;slf4j.version&gt;1.7.7&lt;/slf4j.version&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
                  &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
                  &lt;version&gt;${slf4j.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
                  &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
                  &lt;version&gt;${slf4j.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;commons-logging&lt;/groupId&gt;
                  &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
                  &lt;version&gt;1.1.1&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com&lt;/groupId&gt;
                  &lt;artifactId&gt;ojdbc&lt;/artifactId&gt;
                  &lt;version&gt;6&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.jcraft&lt;/groupId&gt;
                  &lt;artifactId&gt;jsch&lt;/artifactId&gt;
                  &lt;version&gt;0.1.51&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
                  &lt;artifactId&gt;javax.ws.rs-api&lt;/artifactId&gt;
                  &lt;version&gt;2.0&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.googlecode.json-simple&lt;/groupId&gt;
                  &lt;artifactId&gt;json-simple&lt;/artifactId&gt;
                  &lt;version&gt;1.1&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;commons-lang&lt;/groupId&gt;
                  &lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
                  &lt;version&gt;2.3&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;junit&lt;/groupId&gt;
                  &lt;artifactId&gt;junit&lt;/artifactId&gt;
                  &lt;version&gt;4.8.1&lt;/version&gt;
                  &lt;scope&gt;test&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
                  &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
                  &lt;version&gt;${javax.servlet.version}&lt;/version&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-container-servlet&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-media-moxy&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.test-framework.providers&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-test-framework-provider-simple&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
                  &lt;scope&gt;test&lt;/scope&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.ext&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-spring3&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.ext&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-declarative-linking&lt;/artifactId&gt;
                  &lt;version&gt;2.19&lt;/version&gt;
              &lt;/dependency&gt; 
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey.ext&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-bean-validation&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-expression&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
                  &lt;artifactId&gt;poi&lt;/artifactId&gt;
                  &lt;version&gt;3.8&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
                  &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
                  &lt;version&gt;1.3.2&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.batch&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-batch-core&lt;/artifactId&gt;
                  &lt;version&gt;${spring.batch.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.batch&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-batch-infrastructure&lt;/artifactId&gt;
                  &lt;version&gt;${spring.batch.version}&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;net.sourceforge.jexcelapi&lt;/groupId&gt;
                  &lt;artifactId&gt;jxl&lt;/artifactId&gt;
                  &lt;version&gt;2.6.3&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
                  &lt;version&gt;${spring.version}&lt;/version&gt;
                  &lt;scope&gt;test&lt;/scope&gt;
              &lt;/dependency&gt;
  &lt;/dependencies&gt;
    &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.5.1&lt;/version&gt;
                  &lt;inherited&gt;true&lt;/inherited&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Below is my web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;xyz&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;!-- &lt;servlet&gt;
          &lt;servlet-name&gt;context&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.context.ContextLoaderServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1000&lt;/load-on-startup&gt;
      &lt;/servlet&gt; --&gt;
    &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;classpath*:application-context.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
      &lt;listener-class&gt;
            org.springframework.web.context.ContextLoaderListener
      &lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;servlet&gt;
          &lt;servlet-name&gt;abc&lt;/servlet-name&gt;
           &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
              &lt;param-value&gt;com.ecable.endpoint&lt;/param-value&gt;
          &lt;/init-param&gt;
  
          &lt;load-on-startup&gt;1001&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;abc&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>And my responseObject is below with getters and setters </p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "myresponse", propOrder = {
      "cityId",
      "cityDesc"
  })
  @Component
  public class Myresponse {
  </code></pre>
  
  <p>And my endpoint is below</p>
  
  <pre><code>@Path("/fetch")
  public class LoginWSEndPoint {
      @Autowired
      private Myresponse myresponse ;
  
      @GET
      @Path("/get")
      @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
      @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
      public Response responseMsg(){
          myresponse.setCityDesc("desc city");
          myresponse.setCityId(" city id");
          return Response.status(200).entity(loginResponse).build();
  
      }
  </code></pre>
  
  <p>Any help is appreciated.</p>
  
  <p>Please see the logs</p>
  
  <pre><code>Jul 03, 2015 12:34:05 PM org.glassfish.jersey.server.spring.AutowiredInjectResolver getBeanFromSpringContext
  WARNING: No beans found. Resolution failed for type class com.objects.MyResponse.
  Jul 03, 2015 12:34:06 PM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [abc] in context with path [/xyz] threw exception [java.lang.NullPointerException] with root cause
  java.lang.NullPointerException
      at com.ecable.endpoint.LoginWSEndPoint.responseMsg(LoginWSEndPoint.java:24)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
      at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:140)
      at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:158)
      at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
      at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:101)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:353)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:343)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
      at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:237)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:318)
      at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:211)
      at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:982)
      at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:359)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>Also please see my beans.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd"&gt;
      &lt;context:component-scan base-package="com.objects" /&gt;
      &lt;context:annotation-config /&gt;
  &lt;/beans&gt;
  </code></pre>