title: Injection of the sessionFactory not working
body: <p>I'm new with Spring and I want to inject the sessionFactory and its not working at all. I'm starting a web server Jetty and then I load the context. After i start a GWT web application, I make a call on the server side and I try to get some info but I get a null pointer. There is no error at all so it make it difficult to know where the problem is. I know its suppose to work because I saw it working on a project I worked on some times ago. Any help will be appreciate. (Sorry for my possibly bad english)</p>
  
  <p>Here is the context.xml :</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  
   &lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:context="http://www.springframework.org/schema/context"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:security="http://www.springframework.org/schema/security"
     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
     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
     http://www.springframework.org/schema/security http://www.springframework.org/schema
      /security/spring-security-3.0.xsd"&gt;
  
  
     &lt;!--  Standard spring initialization --&gt;
     &lt;context:component-scan base-package="com.test"&gt;
  
     &lt;/context:component-scan&gt;
  
     &lt;tx:annotation-driven transaction-manager="txManager"/&gt;
  
     &lt;!-- Connection to the database--&gt;
     &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-
      method="close"&gt;
  
     &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
     &lt;property name="url" value="jdbc:mysql://localhost:3306/test" /&gt;
     &lt;property name="username" value="root" /&gt;
     &lt;property name="password" value="123456789" /&gt;
     &lt;/bean&gt;
  
     &lt;!-- Hibernate session factory--&gt;
     &lt;bean id="jpaSessionFactory"   
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
    &lt;property name="dataSource" ref="dataSource" /&gt;
    &lt;property name="packagesToScan" value="com.domain"/&gt;
    &lt;property name="namingStrategy" &gt;
      &lt;bean class="org.hibernate.cfg.ImprovedNamingStrategy" /&gt;
    &lt;/property&gt;
    &lt;property name="hibernateProperties"&gt;
      &lt;props&gt;
          &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5Dialect&lt;/prop&gt;
          &lt;prop key="show_sql"&gt;true&lt;/prop&gt;
          &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
      &lt;/props&gt;
    &lt;/property&gt;
     &lt;/bean&gt;
  
     &lt;!-- Hibernate session factory --&gt;   
     &lt;bean id="txManager"    
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
    &lt;property name="sessionFactory" ref="jpaSessionFactory" /&gt;
     &lt;/bean&gt;
  
   &lt;/beans&gt;
  </code></pre>
  
  <p>Here is the main : </p>
  
  <pre><code>    public static void main(String[] args) {
  
          ContextHandlerCollection contexts = new ContextHandlerCollection();
  
          contexts.setHandlers(new Handler[] 
          { new AppContextBuilder().buildWebAppContext()});
  
          final JettyServer jettyServer = new JettyServer();
          jettyServer.setHandler(contexts);
          Runnable runner = new Runnable() {
              @Override
              public void run() {
                  new ServerRunner(jettyServer);
              }
          };
          EventQueue.invokeLater(runner);
  
          new ClassPathXmlApplicationContext("context.xml");
      }
  </code></pre>
  
  <p>Here is the class Test where I want the injection :</p>
  
  <pre><code>@Component("test")
  public class TEST{
  
      @Resource(name="jpaSessionFactory")
      private SessionFactory sessionFactory;
  
      @SuppressWarnings("unchecked")
      @Transactional(readOnly = true)
      public  List&lt;Personne&gt; getPersonnes() {
  
          Session s = sessionFactory.getCurrentSession();
  
          Query query = s.createQuery("from Person");
  
          return query.list();
      }
  }
  </code></pre>
  
  <p>Here is the server side from the application (not shown completely)</p>
  
  <pre><code>/*** The server side implementation of the RPC service.
   */
  @SuppressWarnings("serial")
  public class GreetingServiceImpl extends RemoteServiceServlet implements
      GreetingService {
  
  @Resource
  private TEST t;
  
  public String greetServer(String input) throws IllegalArgumentException {
      // Verify that the input is valid. 
      if (!FieldVerifier.isValidName(input)) {
          // If the input is not valid, throw an IllegalArgumentException 
                          back to
          // the client.
          throw new IllegalArgumentException(
                  "Name must be at least 4 characters long");
      }
  
      t.getPersons();  // NULL pointer here
  </code></pre>
  
  <p>.........................</p>
  
  <p>The MySQL tables are created like it should, so all the scanning seems to work.</p>
  
  <p>Thanks</p>
  
  <p>Bob</p>