title: The hibernate sessionFactory is always null in my DAO for a regular java class
body: <p>I see so many questions on this and have tried numerous permutations of the many different solutions and none have worked.</p>
  
  <p>I have a dao that requires a hibernate sessionfactory to do transactions.  In the SpringMVC Context I've seen it working but the dao included in a java class is null.  There is no error in catalina.out:</p>
  
  <p>my full applicationContext.xml(because I really think the problem is here somewhere):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:context="http://www.springframework.org/schema/context"
  
     xsi:schemaLocation=
     "http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/tx 
      http://www.springframework.org/schema/tx/spring-tx.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
  &lt;!-- Scan classpath for annotations (eg: @Service, @Repository etc)--&gt;
  
  &lt;context:annotation-config/&gt;
  
  &lt;context:component-scan base-package="com.shazam.di.*" /&gt;
  
  &lt;!-- JNDI Data Source. this works I can get to it independent of spring--&gt;
  &lt;bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"
  scope="singleton"&gt;
      &lt;property name="jndiName" value="jdbc/dostudentdb"/&gt;
      &lt;property name="resourceRef" value="true"/&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven/&gt;
  
  &lt;!-- Hibernate Session Factory --&gt;
  &lt;bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="myDataSource"/&gt;
      &lt;property name="packagesToScan"&gt;
      &lt;array&gt;
          &lt;value&gt;com.shazam.di.spring.coursemgmt.dao&lt;/value&gt;
      &lt;/array&gt;
      &lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;
              &lt;!--&lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;--&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
          &lt;/props&gt;        
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Hibernate Transaction Manager --&gt;
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="mySessionFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;!--I've alternated between contructor, properties for getters &amp; setters --&gt; 
  &lt;!--here, and nothing (just letting it get autowired into the private--&gt;
  &lt;!--SessionFactory instance, no effing cigar!!--&gt;
  &lt;bean id="studentDAO" class="org.shazam.di.spring.coursemgmt.dao.StudentDAO"&gt;
      &lt;!--&lt;constructor-arg type="SessionFactory" value="mySessionFactory"/&gt;--&gt;
      &lt;property name="insertUserProfile" ref="insertUserProfile"/&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>The class for which the DAO but not the sessionFactory can be found:</p>
  
  <pre><code>@Component
  public class CheckClassAccess
  {
      @Autowired 
      private static StudentDAO studentDAO;...
  </code></pre>
  
  <p>The beginning of the DAO(tried autwiring only getter &amp; setters and a constructor):</p>
  
  <pre><code>@Repository
  @SuppressWarnings({"unchecked", "rawtypes"})
  public class StudentDAO {
  
      @Autowired 
      private SessionFactory sessionFactory;
  etc...
  </code></pre>
  
  <p>The WEB XML Spring lines:</p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;classpath*:WEB-INF/applicationContext.xml&lt;/param-value&gt;
  &lt;/context-param&gt;    
  and then a little later...
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt; 
  </code></pre>
  
  <p>The only other caveat to this is that I'm attempting to get this to work within an opensource java cms called Opencms.  But not sure that's relevant as the files that I'm wiring to are vanilla java support class, not controllers or anything(not really looking to do Spring-MVC with it just yet).</p>
  
  <p>In fact all of this works in a Spring MVC servlet-context on a seperate smaller application but I just cannot seem to get these same objects/annotations to register in the applicationContext.</p>