title: Grizzly, Jersey and Spring auto-wiring issue
body: <p>I am using Grizzly as a web server to create standalone REST service with Jersey. I also want to use Spring IoC in the application but I ran into problems with auto-wiring beans.</p>
  
  <p>To create the server I run this in my main() method:</p>
  
  <pre><code>HttpServer server = null;
  
  try {
      ResourceConfig rc = new PackagesResourceConfig("");
      ConfigurableApplicationContext cac = new ClassPathXmlApplicationContext("classpath*:/spring-context.xml");          
      IoCComponentProviderFactory factory = new SpringComponentProviderFactory(rc, 
  
      server = GrizzlyServerFactory.createHttpServer("http://localhost:5555", rc, factory);
      System.in.read();
  } catch (Exception e) {
      e.printStackTrace();
  } finally {
      try {
         if (server != null) {
            server.stop();
         }
      } catch (Exception e) {
             e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>My spring-context.xml contains just below:</p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="com.test"/&gt;
  </code></pre>
  
  <p>I want to auto-wire BO object in my Jersey resource class:</p>
  
  <pre><code>@Path("/test")
  @Service
  public class Test {
  
      @Autowired
      private testBO testBo;
      ....
  
      @GET
      @Path("/info")
      public String getInfo() {
         return testBo.get();
      }
  
  }
  </code></pre>
  
  <p>Now, whenever I call a method in the Test class that references testBo, I am getting <strong>NullPointerException</strong>, which I think means the bean was not auto-wired.</p>
  
  <p>testBO class has @Component annotation. Also all relevant beans are part of "com.test" package or its subpackages.</p>
  
  <p>Anyone has any idea what am I doing wrong?</p>
  
  <p>As requested stack trace for NullPointerException below:</p>
  
  <pre><code>java.lang.NullPointerException
      at com.test.Test.getInfo(Test.java:27)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      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:288)
      at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
      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:1469)
      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
      at com.sun.jersey.server.impl.container.grizzly2.GrizzlyContainer._service(GrizzlyContainer.java:215)
      at com.sun.jersey.server.impl.container.grizzly2.GrizzlyContainer.service(GrizzlyContainer.java:185)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:162)
      at org.glassfish.grizzly.http.server.HttpHandlerChain.service(HttpHandlerChain.java:195)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:162)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:160)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$3.execute(ExecutorResolver.java:95)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:444)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:364)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:290)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:133)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:76)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:63)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:823)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:116)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$000(WorkerThreadIOStrategy.java:55)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$1.run(WorkerThreadIOStrategy.java:98)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:508)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:488)
      at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>I am also seeing that in the console output:</p>
  
  <pre><code>03-Aug-2013 17:46:33 org.springframework.context.support.AbstractApplicationContext prepareRefresh
  INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@131f71a: startup date [Sat Aug 03 17:46:33 BST 2013]; root of context hierarchy
  03-Aug-2013 17:46:33 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1971afc: defining beans []; root of factory hierarchy
  </code></pre>