Q:

REST: java.lang. NullPointerException on @autowired aircraftService

I am currently trying to create a restful webservice in java(jersey) which will use MongoDB. 
I'm trying to return all of the entries currently in a mongodb database-collection.  
While running the tomcat server im getting the following error:
Sep 30, 2014 1:02:21 PM com.sun.jersey.spi.container. ContainerResponse mapMappableContainerException
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang. NullPointerException
    at rest. Resource. AircraftResource.findAllAircraft(AircraftResource.java:46)
    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 com.sun.jersey.spi.container. JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch. AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    at com.sun.jersey.server.impl.model.method.dispatch. ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules. HttpMethodRule.accept(HttpMethodRule.java:302)
    at com.sun.jersey.server.impl.uri.rules. ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules. RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules. RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application. WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
    at com.sun.jersey.server.impl.application. WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
    at com.sun.jersey.server.impl.application. WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    at com.sun.jersey.server.impl.application. WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    at com.sun.jersey.spi.container.servlet. WebComponent.service(WebComponent.java:409)
    at com.sun.jersey.spi.container.servlet. ServletContainer.service(ServletContainer.java:540)
    at com.sun.jersey.spi.container.servlet. ServletContainer.service(ServletContainer.java:715)
    at javax.servlet.http. HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core. ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core. ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server. WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core. ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core. ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core. StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core. StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator. AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core. StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves. ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves. AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core. StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector. CoyoteAdapter.service(CoyoteAdapter.java:534)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
    at org.apache.coyote. AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net. NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
    at org.apache.tomcat.util.net. NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
    at java.util.concurrent. ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent. ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads. TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang. Thread.run(Unknown Source)

Sep 30, 2014 1:02:21 PM org.apache.catalina.core. StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Jersey REST Service] in context with path [/projectPiranha] threw exception
java.lang. NullPointerException
    at rest. Resource. AircraftResource.findAllAircraft(AircraftResource.java:46)
    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 com.sun.jersey.spi.container. JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch. AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    at com.sun.jersey.server.impl.model.method.dispatch. ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules. HttpMethodRule.accept(HttpMethodRule.java:302)
    at com.sun.jersey.server.impl.uri.rules. ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules. RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules. RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application. WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
    at com.sun.jersey.server.impl.application. WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
    at com.sun.jersey.server.impl.application. WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    at com.sun.jersey.server.impl.application. WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    at com.sun.jersey.spi.container.servlet. WebComponent.service(WebComponent.java:409)
    at com.sun.jersey.spi.container.servlet. ServletContainer.service(ServletContainer.java:540)
    at com.sun.jersey.spi.container.servlet. ServletContainer.service(ServletContainer.java:715)
    at javax.servlet.http. HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core. ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core. ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server. WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core. ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core. ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core. StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core. StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator. AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core. StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves. ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves. AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core. StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector. CoyoteAdapter.service(CoyoteAdapter.java:534)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
    at org.apache.coyote. AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net. NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
    at org.apache.tomcat.util.net. NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
    at java.util.concurrent. ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent. ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads. TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang. Thread.run(Unknown Source)

This is my resource class
    @Component
    @Path("aircraft/")
    @ManagedBean 
    public class AircraftResource implements IAircraftResource {

        static final Logger logger = LoggerFactory.getLogger(AircraftResource.class);
        @Autowired 
        private IAircraftService aircraftService;

        @Context 
            private UriInfo uriInfo;

        @Override
        @GET
        @Produces({MediaType. APPLICATION_JSON})
        public List<Aircraft> findAllAircraft()
        {
        List<Aircraft> results = aircraftService.findAllAircraft();
        return results;
        }

aircraftService is null.  
But this is my Service class which implements the IAircraftService interface:
@Service
@Scope("singleton")
public class AircraftService implements IAircraftService {

    static final Logger logger = LoggerFactory.getLogger(AircraftService.class);

    @Autowired private IAircraftRepository aircraftRepository;

    @Override
    public List<Aircraft> findAllAircraft() 
    {
        List<Aircraft> results = aircraftRepository.findAllAircraft();

        logger.info("Amount of Air-vehicles: {}", results.size());
        logger.info("Results: {}", results);

        return results;
    }

My applicationContext.xml:
<? xml version="1.0" encoding="UTF-8"? >
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <context:annotation-config/>

  <context:component-scan base-package="rest">
    <context:exclude-filter type="annotation" expression="org.springframework.context.annotation. Configuration"/>
  </context:component-scan>

  <bean id="mongoTemplate" class="org.springframework.data.mongodb.core. MongoTemplate">
    <constructor-arg name="mongo" ref="mongo"/>
    <constructor-arg name="databaseName" value="iffdb"/>
  </bean> 

  <bean id="mongo" class="org.springframework.data.mongodb.core. MongoFactoryBean">
    <property name="host" value="localhost"/>
  </bean>

  <bean class="org.springframework.dao.annotation. PersistenceExceptionTranslationPostProcessor"/>

</beans>

Please help me out! 

A:

Its propably because of this line:
List<Aircraft> results = aircraftService.findAllAircraft();

aircraftService is not set yet, so its null.  Calling a method on it, will return a nullpointerexception.