spring中配置二級緩衝

來源:互聯網
上載者:User

1.首先,在spring的hibernate配置裡(我的是applicationContext-hibernate.xml) 加上如下屬性:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">         
  <property name="dataSource">
   <ref bean="dataSource"/>
  </property>
  <property name="mappingResources">
   <list>
    <value>org/appfteaching/model/TArticleclass.hbm.xml</value>
   </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
          <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
          <prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop>
          <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
          <prop key="hibernate.cache.use_query_cache">true</prop>
          <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
   </props>   
  </property>  
 </bean> 

2.其次,在src目錄下的ehcache.xml中配置如下資訊(如果是預設ehcache.xml則會有<cache name="sampleCache1">和<cache name="sampleCache2>",去掉)

<cache name="org.hibernate.cache.StandardQueryCache"
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="300"
        timeToLiveSeconds="4200"
        overflowToDisk="true"
        />

    <!-- Sample cache named sampleCache2
        This cache contains 1000 elements. Elements will always be held in memory.
        They are not expired. -->

    <cache name="org.hibernate.cache.UpdateTimestampsCache"
        maxElementsInMemory="5000"
        eternal="true"
        timeToIdleSeconds="0"
        timeToLiveSeconds="0"
        overflowToDisk="false"
        />

3.將你要緩衝的model加進ehcache.xml裡

<cache name="org.appfteaching.model.TArticleclass"
     maxElementsInMemory="1000"
        eternal="false"
        timeToIdleSeconds="100"
        timeToLiveSeconds="4200"
        overflowToDisk="true"
     />  

4.最後一步,在TArticleclass.hbm.xml裡加上

<cache usage="read-write"/>

啟動Tomcat,如發現如下錯誤

Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.
Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.

則是第二步沒有做,加上即可.配置完畢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.