Spring + myBatis + ehcache構成
Spring Mybatis Ehcache Configuration
まず、関連するライブラリパッケージ参照をPOMに追加します。
org.mybatis
mybatis
${mybatis.version}
org.mybatis
mybatis-spring
${mybatis.spring.version}
org.mybatis
mybatis-ehcache
1.0.0
net.sf.ehcache
ehcache-core
${ehcache.version}
org.springframework
spring-context
${spring.version}
org.springframework
spring-context-support
${spring.version}
次に、ehcache構成を追加します:ehcache.xml
eternal='false'
timeToIdleSeconds='120'
timeToLiveSeconds='120'
overflowToDisk='true'
maxElementsOnDisk='10000000'
diskPersistent='false'
diskExpiryThreadIntervalSeconds='120'
memoryStoreEvictionPolicy='LRU' />
3番目に、Spring構成ファイルapplication-context.xmlに構成を追加します。
Beansヘッダーへの参照を追加します。
xmlns:p='http://www.springframework.org/schema/p'
xmlns:cache='http://www.springframework.org/schema/cache'
xsi:schemaLocationに追加
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
ehcache Beanを追加します:
p:cacheManager-ref='ehcache'/>
p:configLocation='classpath:ehcache.xml' p:shared='true'/>
第四に、mybatis-config.xmlを変更します。
追加:
このステップは省略できます。mybatisのデフォルトのcacheEnableは開いています
5番目に、キャッシュを使用する必要があるマッパーを追加します。
実際の測定では、両者に違いは見られませんでした。関連情報によると、LogginEhcacheがログを開きました。