Getting No bean named 'sessionFactory' error when using OpenSessionInViewFilter

前端 未结 1 1855
南旧
南旧 2021-01-14 06:38

I am using Hibernate\'s lazy loading, and after adding OpenSessionInViewFilter to my web.xml I started to get sessionFactory missing exception, even after defining the sessi

相关标签:
1条回答
  • 2021-01-14 07:01

    Try moving the following configuration to applicationContext.xml

        <bean id="propertyConfigurer"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
              p:location="/WEB-INF/jdbc.properties"/>
    
        <bean id="dataSource"
              class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
              p:driverClassName="${jdbc.driverClassName}"
              p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
              p:password="${jdbc.password}"/>
    
    
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="configLocation">
                <value>classpath:hibernate.cfg.xml</value>
            </property>
            <property name="configurationClass">
                <value>org.hibernate.cfg.AnnotationConfiguration</value>
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.hbm2ddl.auto">update</prop>
                </props>
            </property>
            <property name="annotatedClasses">
                <list>
                    <value>net.crawler.dao.model.ScrapingProperties</value>
                </list>
            </property>
        </bean>
    
        <tx:annotation-driven/>
    
        <bean id="transactionManager"
              class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
    
    0 讨论(0)
提交回复
热议问题