title: What is other alternative to use spring bean without wiring
body: <p>I am using this in my UserDAO and hibernate</p>
  
  <pre><code>@Resource(name="sessionFactory");
  public SessionFactory sessionFactory;
  </code></pre>
  
  <p>For some reason i am not able to link spring beans in my userDAO from 2 different classes.</p>
  
  <p>What is the other alternative of above code i mean something like</p>
  
  <pre><code>SessionFactory sessionFactory = new Sessionfactory()
  </code></pre>
  
  <p>is that ok</p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
    &lt;display-name&gt;testing&lt;/display-name&gt;
  
  
    &lt;filter&gt;
              &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
              &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
              &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
              &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
          /WEB-INF/spring-security.xml
  
          &lt;/param-value&gt;
      &lt;/context-param&gt;
  
  
  
  
    &lt;servlet&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/krams/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;redirect.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>dispatcher-servlet</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:p="http://www.springframework.org/schema/p"
      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/context 
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
  
      &lt;import resource="hibernate-context.xml" /&gt;
  
  
      &lt;mvc:annotation-driven /&gt; 
  
      &lt;bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /&gt;
  
      &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages" /&gt;
  
      &lt;context:component-scan base-package="com.vaannila" /&gt;
  
      &lt;bean id="userService" class="com.vaannila.service.UserServiceImpl" /&gt;
  
      &lt;bean id="userValidator" class="com.vaannila.validator.UserValidator" /&gt;
       &lt;bean id="registrationDAO" class="com.vaannila.dao.RegistrationDAO" /&gt;
       &lt;bean id="userDAO" class="com.vaannila.dao.UserDAO" /&gt;
  
  
  
  
  
     &lt;bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"&gt;
        &lt;property name="velocityProperties"&gt;
           &lt;value&gt;
            resource.loader=class
            class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
           &lt;/value&gt;
        &lt;/property&gt;
     &lt;/bean&gt;
  
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>hibernate-context</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:p="http://www.springframework.org/schema/p" 
          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-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/context
              http://www.springframework.org/schema/context/spring-context-3.0.xsd
              "&gt;
  
      &lt;context:property-placeholder location="/WEB-INF/spring.properties" /&gt;
  
      &lt;!-- Enable annotation style of managing transactions --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;   
  
      &lt;!-- Declare the Hibernate SessionFactory for retrieving Hibernate sessions --&gt;
      &lt;!-- See http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.html --&gt;                           
      &lt;!-- See http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/SessionFactory.html --&gt;
      &lt;!-- See http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/Session.html --&gt;
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
                   p:dataSource-ref="dataSource"
                   p:configLocation="${hibernate.config}"
                   p:packagesToScan="com.vaannila"/&gt;
  
      &lt;!-- Declare a datasource that has pooling capabilities--&gt;   
      &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
                  destroy-method="close"
                  p:driverClass="${app.jdbc.driverClassName}"
                  p:jdbcUrl="${app.jdbc.url}"
                  p:user="${app.jdbc.username}"
                  p:password="${app.jdbc.password}"
                  p:acquireIncrement="5"
                  p:idleConnectionTestPeriod="60"
                  p:maxPoolSize="100"
                  p:maxStatements="50"
                  p:minPoolSize="10" /&gt;
  
      &lt;!-- Declare a transaction manager--&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
                  p:sessionFactory-ref="sessionFactory" /&gt;
  
  &lt;/beans&gt;
  </code></pre>