title: Migrating Spring 3.1 to Spring 4: org.springframework.web.context.support.ServletContextFactoryBean
body: <p>I´m migrating a Spring 3.1 + Hibernate 4 Web application to a Jboss 6.1 server with Spring 4.0.5 and Hibernate 4. Here´s my problem, in the original project, in my "applicationContext.xml" exists a bean like this one : </p>
  
  <p><code>&lt;bean id="servletContext" class="org.springframework.web.context.support.ServletContextFactoryBean"/&gt;</code></p>
  
  <p>My problem is that Spring 4 doesn´t have that library anymore. I need to know if exist an equivalent way to define this bean in Spring 4.0.5. I really apreciated any help can give me. </p>
  
  <p>This is how looks my code where I use the servletContext Bean:</p>
  
  <pre><code>public class Environment {
  
      private Logs log;           
  
      private ServletContext context;
      private Scheduler quartzSched;
      private SocketPool socketPool;
      private WorkerSocket workerSocket;
      private SocketPoolFactory socketPoolFactory;
      private JsonObject catalog;
      private HashMap&lt;String, Object&gt; connections;
  
      private TerminalDao terminalDao;
      private TerminalItemDao terminalItemDao;
      private UsuarioDao usuarioDao;
      private PaymentSystemDao paymentSystemDao;
      private MensajeDao  mensajeDao; 
      private TransacDao transacDao;
      private TermPaySysDao termPaySysDao;
      private ComprobanteDao comprobanteDao;
      private String paymentSystem;
  
  
      public Environment(String paymentSystem, boolean setSchedulerFactoryBean) throws Exception {
          super();
          this.paymentSystem = paymentSystem;
          ApplicationContext ctx =  new ClassPathXmlApplicationContext("applicationContext.xml");
          Services services = (Services) ctx.getBean("Services");         
          this.catalog = services.getCatalog();
          this.connections = services.getConnections();       
          this.transacDao = (TransacDao) ctx.getBean("transacDao");
          this.terminalDao = (TerminalDao) ctx.getBean("terminalDao");
          this.usuarioDao = (UsuarioDao) ctx.getBean("usuarioDao");
          this.terminalItemDao = (TerminalItemDao) ctx.getBean("terminalItemDao");
          this.paymentSystemDao = (PaymentSystemDao) ctx.getBean("paymentSystemDao");
          this.mensajeDao = (MensajeDao) ctx.getBean("mensajeDao");
          this.termPaySysDao = (TermPaySysDao) ctx.getBean("termPaySysDao");
          this.comprobanteDao = (ComprobanteDao) ctx.getBean("comprobanteDao");
  
  
          if(setSchedulerFactoryBean)
              this.quartzSched = (Scheduler) ctx.getBean("schedulerFactoryBean");; //OJO CON ESTO este deberia salir bien
  
          JsonObject PS = catalog.get(paymentSystem).getAsJsonObject();
  
          if(PS.get("ConnectionType").getAsString().equals("SocketPool")){
              this.socketPool = (SocketPool) services.getConnections().get(paymentSystem+"_SocketPool");
              this.socketPoolFactory = (SocketPoolFactory) services.getConnections().get(paymentSystem+"_SocketPoolFactory");     
          }else {
              this.socketPool = null;
              this.socketPoolFactory = null;      
          }
          this.workerSocket = null;
  
          this.context = (ServletContext)ctx.getBean("servletContext"); //HERE I USE THE BEAN
          this.log= new Logs();
  
  
      }
  </code></pre>
  
  <p>Here I add Services.java, this is my class that use ServletContext as parameter.</p>
  
  <pre><code>package com.globalcca.pos_movil_tran.services;
  
  import java.io.File;
  import java.io.FileFilter;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Properties;
  import java.util.Set;
  
  
  import javax.servlet.ServletContext;
  
  
  import org.apache.commons.beanutils.ConvertUtils;
  import org.apache.commons.pool.impl.GenericObjectPool.Config;
  
  import org.springframework.beans.factory.annotation.Autowired;
  
  import com.globalcca.pos_movil_desc.modelo.Transac;
  import com.globalcca.posmovil.resourceManager.SocketPool;
  import com.globalcca.posmovil.resourceManager.SocketPoolFactory;
  import com.globalcca.posmovil.resourceManager.WorkerSocket;
  import com.globalcca.posmovil.util.DateConverter;
  import com.globalcca.posmovil.util.TransacConverter;
  import com.globalcca.posmovil.util.PaymentSystemConverter;
  import com.globalcca.pos_movil_desc.modelo.PaymentSystem;
  import com.globalcca.pos_movil_desc.modelo.Transac;
  import com.google.gson.JsonArray;
  import com.google.gson.JsonElement;
  import com.google.gson.JsonObject;
  import com.google.gson.JsonParser;
  import com.google.gson.stream.JsonReader;
  
  public class Services {
  
  JsonObject catalog;
  static HashMap&lt;String, Object&gt; connections;
  static Config SocketPoolConfig = new Config();
  private static Logs log = new Logs();
  @Autowired ServletContext servletContext;
  
  public Services( ServletContext context) throws IOException{
  
      ConvertUtils.register(new DateConverter(), java.util.Date.class);
      ConvertUtils.register(new TransacConverter(), Transac.class);               //Se arreglo TransacConverter
      //ConvertUtils.register(new PaymentSystemConverter(), PaymentSystem.class);
  
      FileFilter fileFilter = new FileFilter() {
          public boolean accept(File file) {
              return file.isDirectory();
          }
      };      
      File dir = new File(context.getRealPath("/WEB-INF/classes/Adquiriente/"));
      readSocketPoolProperties(context);
  
      JsonObject catalog = new JsonObject();
      connections = new HashMap&lt;String, Object&gt;();
      JsonParser parser = new JsonParser();
      // This filter only returns directories
      File[] files = dir.listFiles(fileFilter);
      if (files == null) {
          System.out.println("Either dir does not exist or is not a directory");
      } else {
          for (int i=0; i&lt;files.length; i++) 
          {
              // Get path of directory
              String dirpath = files[i].getAbsolutePath();
              String dirname = files[i].getName();
              String catalogPath = dirpath+"/Catalog.cfg";
              String ConnectionModuleConfigPath = dirpath+"/ConnectionModule.cfg";
  
              try{
                  JsonReader reader = new JsonReader(new InputStreamReader(new FileInputStream(catalogPath)));
                  JsonObject PaymentSystem = (JsonObject)parser.parse(reader);                    
                  catalog.add(dirname,PaymentSystem);
                  //initConnection(PaymentSystem,ConnectionModuleConfigPath,parser,dirname);      //Descomentar esto cuando tengamos las conexiones
                  log.info("Loading "+catalogPath+" Successful");
              } catch (FileNotFoundException e) {
                  log.error("Error parsing Catalog.cfg File");
              } 
  
          }
          this.setCatalog(catalog);
      }   
  }
  
  public static void readSocketPoolProperties(ServletContext context){
      String  SocketPoolProp = "/WEB-INF/classes/SocketPool.properties";
      Properties prop = new Properties();
      Boolean error = false; 
      try {
          SocketPoolProp = context.getRealPath(SocketPoolProp);
          prop.load(new FileInputStream(SocketPoolProp));
          SocketPoolConfig.maxIdle = Integer.parseInt(prop.getProperty("MaxIdle"));
          SocketPoolConfig.maxActive = Integer.parseInt(prop.getProperty("MaxActive"));
          SocketPoolConfig.minEvictableIdleTimeMillis = Long.parseLong(prop.getProperty("MinEvictableIdleTimeMillis"));
          SocketPoolConfig.testOnBorrow = Boolean.parseBoolean(prop.getProperty("TestOnBorrow"));
          SocketPoolConfig.maxWait = Long.parseLong(prop.getProperty("MaxWait"));
      } catch (IOException e) {
          log.error("Error Loading SocketPool.properties File");
          error = true;
      }
  
      if(error){
          log.info("Using Default Values for SocketPool config");
          SocketPoolConfig = new Config();
          SocketPoolConfig.maxIdle = SocketPool.DEFAULT_MAX_IDLE;
          SocketPoolConfig.maxActive = SocketPool.DEFAULT_MAX_ACTIVE;
          SocketPoolConfig.minEvictableIdleTimeMillis = SocketPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
          SocketPoolConfig.testOnBorrow = SocketPool.DEFAULT_TEST_ON_BORROW;
          SocketPoolConfig.maxWait = SocketPool.DEFAULT_MAX_WAIT;
      }else{
          log.info("Loading "+SocketPoolProp+" Successful");
      }
  }
  
  public static void initConnection(JsonObject PaymentSystem, String ConnectionModuleConfigPath, JsonParser parser,String PSName) {
  
      JsonReader reader;
      try {
          reader = new JsonReader(new InputStreamReader(new FileInputStream(ConnectionModuleConfigPath)));
  
      JsonObject ConnectionsConfig = (JsonObject)parser.parse(reader);                    
  
      if(ConnectionsConfig.get("Type").getAsString().equals("SocketPool")){
          initSocketPool(PaymentSystem, ConnectionModuleConfigPath,parser,PSName, ConnectionsConfig);
          log.info("Initialization of SocketPool Successful");
  
      }else if(ConnectionsConfig.get("Type").getAsString().equals("ServerSocket")){
          initServerSocket(PaymentSystem, ConnectionModuleConfigPath,parser,PSName, ConnectionsConfig); 
          log.info("Initialization of ServerSocket Successful");
  
      }
      PaymentSystem.addProperty("ConnectionType", ConnectionsConfig.get("Type").getAsString());
  
      } catch (IOException e) {
          log.error("Error Initializing Connections");
          log.error(e);
      }
  
  }
  
  
  private static void initServerSocket(JsonObject PaymentSystem, String socketConfigPath, JsonParser parser,String PSName, JsonObject ConnectionsConfig) throws IOException{
  
      JsonObject address = ConnectionsConfig.getAsJsonObject("Connections");
  
      Set&lt;Map.Entry&lt;String, JsonElement&gt;&gt; map = address.entrySet();
      Iterator&lt;Map.Entry&lt;String, JsonElement&gt;&gt; iterator = map.iterator();
      int size = map.size();
      WorkerSocket [] sSockets = new WorkerSocket[size];
  
      for( int k = 0; k &lt; size; k++ )
      { 
          String IP = iterator.next().getKey();
          int port = address.get(IP).getAsInt();
          sSockets[k] = new WorkerSocket(IP, port);
          log.trace("Server Socket IP:"+IP+" Port:"+port+" Initialized");
          iterator.remove();  
      }
      connections.put(PSName+"_sSockets", sSockets);
  
  }
  
  private static void initSocketPool(JsonObject PaymentSystem, String socketConfigPath, JsonParser parser,String PSName, JsonObject ConnectionsConfig){
  
      SocketPoolFactory spf = new SocketPoolFactory();
      SocketPool sp = new SocketPool(spf,SocketPoolConfig);
      JsonObject address = ConnectionsConfig.getAsJsonObject("Connections");
      try {           
  
          Set&lt;Map.Entry&lt;String, JsonElement&gt;&gt; map = address.entrySet();
          Iterator&lt;Map.Entry&lt;String, JsonElement&gt;&gt; iterator = map.iterator();
          int size = map.size();
  
          for( int k = 0; k &lt; size; k++ )
          { 
              String IP = iterator.next().getKey();
              JsonArray Sockets = address.getAsJsonArray(IP);
  
              for(int i=0;i&lt;Sockets.size();i++)
              {
                  JsonArray Ports = Sockets.get(i).getAsJsonArray();
                  int first = Ports.get(0).getAsInt();
                  int dif = Ports.get(1).getAsInt()-first+1;
                  for(int j=0;j&lt;dif;j++)
                  {
                      sp.addSocket(IP,first+j);
                      log.trace("Pool Socket IP:"+IP+" Port:"+first+j+" Added");
                  }
              }
              iterator.remove();
          }
  
  
      } catch (Exception e) {
          log.error(e);
      }
  
      connections.put(PSName+"_SocketPool", sp);
      connections.put(PSName+"_SocketPoolFactory",spf);
  }
  
  public HashMap&lt;String, Object&gt; getConnections() {
      return connections;
  }
  
  
  public JsonObject getCatalog() {
      return catalog;
  }
  
  public void setCatalog(JsonObject catalog) {
      this.catalog = catalog;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and this is my ApplicationContext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
      &lt;beans default-autowire="byName" 
      xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:tx="http://www.springframework.org/schema/tx"
      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.1.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"&gt;
  
      &lt;context:annotation-config/&gt;
  
      &lt;bean id="dataSource"
          class="org.apache.commons.dbcp.BasicDataSource"&gt;
          &lt;property name="driverClassName" &gt;
              &lt;value&gt;oracle.jdbc.driver.OracleDriver&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="url"&gt;
              &lt;value&gt;jdbc:oracle:thin:@10.0.0.66:1521:bgw&lt;/value&gt;
          &lt;/property&gt; 
          &lt;property name="username"&gt;
              &lt;value&gt;POSMOVIL&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="password"&gt;
              &lt;value&gt;ORACLE&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  
          &lt;!-- Definición de la fábrica de sesiones de Hibernate administrada por Spring --&gt;
      &lt;!-- Mapeo de Hibernate de archivos hbm.xml --&gt;
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
          &lt;property name="mappingResources"&gt;
              &lt;list&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Afiliado.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/App.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Approl.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Archivo.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Banco.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/BloquesHorarios.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Calendario.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Capk.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Comprobante.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Config.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/ConstanteCalendario.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Contactos.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Crl.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Dispone.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Disponibilidad.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Dominio.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Funcion.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Hclaves.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Horario.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Horariodia.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/MasterKey.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Mensaje.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Modulo.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Operador.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/PaymentSystem.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Rol.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Sitio.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Solicitud.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Tarea.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Tarearol.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/TarjetaHabiente.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Terminal.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Terminalitem.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Termpaysys.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Transac.hbm.xml&lt;/value&gt;
                  &lt;value&gt;com/globalcca/pos_movil_desc/modelo/Usuario.hbm.xml&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
  
          &lt;!-- Conexion a la BD especificada en WEB-INF/applicationContex.xml --&gt;
  
          &lt;property name="dataSource"&gt;
              &lt;ref bean="dataSource" /&gt;
          &lt;/property&gt;
  
          &lt;!-- Propiedades de Hibernate --&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.use_sql_comments"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- Configuración del repositorio de datos persistentes --&gt;
  
       &lt;!--
      &lt;bean id="servletContext" class="org.springframework.web.context.support.ServletContextFactoryBean"/&gt;
  
      --&gt;
      &lt;bean id="Services" class="com.globalcca.pos_movil_tran.services.Services"&gt;
          &lt;constructor-arg name="context" ref="servletContext"/&gt;  
      &lt;/bean&gt;
  
      &lt;!-- Definición de las implementaciones (utilizando Hibernate) de los DAO'S --&gt;
      &lt;bean id="afiliadoDao" class="com.globalcca.pos_movil_tran.dao.impl.AfiliadoDaoHibernate"/&gt;
      &lt;bean id="archivoDao" class="com.globalcca.pos_movil_tran.dao.impl.ArchivoDaoHibernate"/&gt;
      &lt;bean id="bancoDao" class="com.globalcca.pos_movil_tran.dao.impl.BancoDaoHibernate"/&gt;
      &lt;bean id="bloqueoDao" class="com.globalcca.pos_movil_tran.dao.impl.BloqueDaoHibernate"/&gt;
      &lt;bean id="calendarioDao" class="com.globalcca.pos_movil_tran.dao.impl.CalendarioDaoHibernate"/&gt;
      &lt;bean id="comprobanteDao" class="com.globalcca.pos_movil_tran.dao.impl.ComprobanteDaoHibernate"/&gt;
      &lt;bean id="configDao" class="com.globalcca.pos_movil_tran.dao.impl.ConfigDaoHibernate"/&gt;
      &lt;bean id="constanteCalendarioDao" class="com.globalcca.pos_movil_tran.dao.impl.ConstanteCalendarioDaoHibernate"/&gt;
      &lt;bean id="disponeDao" class="com.globalcca.pos_movil_tran.dao.impl.DisponeDaoHibernate"/&gt;
      &lt;bean id="disponibilidadDao" class="com.globalcca.pos_movil_tran.dao.impl.DisponibilidadDaoHibernate"/&gt;
      &lt;bean id="dominioDao" class="com.globalcca.pos_movil_tran.dao.impl.DominioDaoHibernate"/&gt;
      &lt;bean id="horarioDao" class="com.globalcca.pos_movil_tran.dao.impl.HorarioDaoHibernate"/&gt;
      &lt;bean id="horarioDiaDao" class="com.globalcca.pos_movil_tran.dao.impl.HorarioDiaDaoHibernate"/&gt;
      &lt;bean id="mensajeDao" class="com.globalcca.pos_movil_tran.dao.impl.MensajeDaoHibernate"/&gt;
      &lt;bean id="operadorDao" class="com.globalcca.pos_movil_tran.dao.impl.OperadorDaoHibernate"/&gt;
      &lt;bean id="paymentSystemDao" class="com.globalcca.pos_movil_tran.dao.impl.PaymentSystemDaoHibernate"/&gt;
      &lt;bean id="sitioDao" class="com.globalcca.pos_movil_tran.dao.impl.SitioDaoHibernate"/&gt;
      &lt;bean id="solicitudDao" class="com.globalcca.pos_movil_tran.dao.impl.SolicitudDaoHibernate"/&gt;
      &lt;bean id="tarjetaHabienteDao" class="com.globalcca.pos_movil_tran.dao.impl.TarjetaHabienteDaoHibernate"/&gt;
      &lt;bean id="terminalDao" class="com.globalcca.pos_movil_tran.dao.impl.TerminalDaoHibernate"/&gt;
      &lt;bean id="terminalItemDao" class="com.globalcca.pos_movil_tran.dao.impl.TerminalItemDaoHibernate"/&gt;
      &lt;bean id="termPaySysDao" class="com.globalcca.pos_movil_tran.dao.impl.TermPaySysDaoHibernate"/&gt;
      &lt;bean id="transacDao" class="com.globalcca.pos_movil_tran.dao.impl.TransacDaoHibernate"/&gt;
      &lt;bean id="usuarioDao" class="com.globalcca.pos_movil_tran.dao.impl.UsuarioDaoHibernate"/&gt;
  
      &lt;!-- Definición del manejador de transacciones de Spring --&gt;
      &lt;bean id="transactionManager"
            class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- Activar el comportamiento transaccional de los métodos y --&gt;
      &lt;!-- clases anotados como @Transactional                      --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
  
      &lt;bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false"&gt;
          &lt;property name="configLocation" value="classpath:./classes/quartz.properties"/&gt;
          &lt;property name="waitForJobsToCompleteOnShutdown" value="false" /&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="applicationContextSchedulerContextKey"&gt;
              &lt;value&gt;applicationContext&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="autoStartup"&gt;
                  &lt;value&gt;true&lt;/value&gt;
          &lt;/property&gt;     
      &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>The Services bean use the servlet context, and i use this bean in the Environment class. Can You give a solution with @Autowired? </p>
  
  <p>Can someone take this code and give an example of how to use @Autowired?? </p>
  
  <p>I try to use @Autowired in my class Services and still giving me null. </p>
  
  <p>Please i need help </p>