title: How to properly utilize dependency injection within static context
body: <p>While my application is a web application, it doesn't use much of Spring's web controllers.  It's just REST (jersey) and sockets.  Only about half of my application uses dependency injection.  My application is initialized within my <code>main()</code>.  </p>
  
  <pre><code>ServletRegistration jerseyServletRegistration = ctx.addServlet("JerseyServlet", new SpringServlet());
  jerseyServletRegistration.setInitParameter("com.sun.jersey.config.property.packages", "com.production.resource");
  jerseyServletRegistration.setInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.production.resource.ResponseCorsFilter");
  jerseyServletRegistration.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", Boolean.TRUE.toString());
  jerseyServletRegistration.setInitParameter("com.sun.jersey.config.feature.DisableWADL", Boolean.TRUE.toString());
  jerseyServletRegistration.setInitParameter("org.codehaus.jackson.map.DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY", Boolean.TRUE.toString());
  jerseyServletRegistration.setLoadOnStartup(1);
  
  jerseyServletRegistration.addMapping("/api/*");
  
  //add atmosphere support
  ServletRegistration socketRegistration = ctx.addServlet("AtmosphereServlet", new SocketInitializer());
  socketRegistration.setLoadOnStartup(1);
  //socketRegistration.addMapping("/socket/*");
  
  //deploy
  logger.info("Deploying server...");
  ctx.deploy(server);
  
  server.start();
  
  //start the production process
  Production.init();
  
  System.in.read();
  server.stop();
  </code></pre>
  
  <p>Within the <code>Production</code> class I load my services via <code>ApplicationContextProvider</code>.  <strong>Is there a better way to do this that would allow me to load all my resources via dependency injection?</strong></p>
  
  <pre><code>public static void init() {
      //add hook to trigger Production Shutdown sequence
      Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
          public void run() {
              Production.shutdown();
          }
      }));
  
      logger.info("Initializing production workflows...");
      productionService = (ProductionService) ApplicationContextProvider.getApplicationContext().getBean("productionService");
  
      //load active workflows into memory
      WorkflowService workflowService = (WorkflowService) ApplicationContextProvider.getApplicationContext().getBean("workflowService");
      for (WorkflowEntity workflowEntity : workflowService.findActive()) {
          logger.info("      - "+workflowEntity.getName()+"");
          workflowList.add(Workflow.factory(workflowEntity));
      }
  
      bootup();
  
      logger.info("Production initialized");
  }
  </code></pre>