Spring MVC+Hibernate3 中遇到的問題

來源:互聯網
上載者:User

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/config/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Could not instantiate cache implementation

……

……

……

先把這段異常資訊google一把後,得到大部分的解決方案都說是包衝突,在經過一系列的實驗發現根本就不是一回事,繼續尋找下列異常資訊。


Caused by: org.hibernate.HibernateException: Could not instantiate cache implementation


……

……

……

Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]

 


隱約得知緩衝配置方面出現問題,發現問題後順著指示找到了applicationContext.xml檔案中的這段配置,提示的意思大概為緩衝不可用,在添加了緩衝配置後一切正常。


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>

                <!-- 添加緩衝配置-->


               <prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
            </props>
        </property>
       
        <!-- hbm.xml檔案載入方式-->
         <property name="mappingLocations">
            <list>
                <value>classpath*:/com/train/entity/admin/hbm/*.hbm.xml</value>
                <value>classpath*:/com/train/entity/common/hbm/*.hbm.xml</value>
            </list>
        </property>
        
    </bean>


雖然報的異常與網上其他人幾乎相同,但還是有不一致的地方,對症下藥方可藥到病除。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.