maven项目中ssm整合ehcache

一、maven添加Ehcache核心包

   <dependency>
       <groupId>net.sf.ehcachegroupId>
       <artifactId>ehcacheartifactId>
       <version>2.7.5version>
   dependency>
   <dependency>
       <groupId>com.googlecode.ehcache-spring-annotationsgroupId>
       <artifactId>ehcache-spring-annotationsartifactId>
       <version>1.2.0version>
   dependency>

二、添加配置文件

  在资源文件夹下(通常是src/main/resources/) 添加 ehcache.xml
  


<ehcache>
    
    <diskStore path="java.io.tmpdir" />

    
    
    
    
    
    
    

    
    <defaultCache maxElementsInMemory="10000" eternal="false"
        overflowToDisk="true" timeToIdleSeconds="10" timeToLiveSeconds="20"
        diskPersistent="false" diskExpiryThreadIntervalSeconds="120" />
ehcache>

三、spring整合ehcache


    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="realm" ref="gpRealm" />
        <property name="cacheManager" ref="cacheManager" />
    bean>

    
    <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
        
        <property name="cacheManagerConfigFile" value="classpath:ehcache.xml" />
    bean>

你可能感兴趣的:(shiro,常用代码)