介绍
这篇文章给大家介绍怎么在春天中对类的级别进行缓存,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
一、配置文件
& lt; ? xml version=?.0“,编码=癎BK" ?比; http://www.springframework.org/schema/beans" & lt; beans  xmlns=?; ,,xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance" ,,xmlns: p=癶ttp://www.springframework.org/schema/p" ,,xmlns:缓存=癶ttp://www.springframework.org/schema/cache" ,,xmlns:上下文=癶ttp://www.springframework.org/schema/context" ,,xsi: schemaLocation=? http://www.springframework.org/schema/beans ,,http://www.springframework.org/schema/beans/spring-beans-4.0.xsd ,,http://www.springframework.org/schema/cache ,,http://www.springframework.org/schema/cache/spring-cache-4.0.xsd ,,http://www.springframework.org/schema/context ,,,http://www.springframework.org/schema/context/spring-context-4.0.xsd"的在 ,,& lt;环境:component-scan ,,,,,基本包=皁rg.crazyit.app.service",/比; ,,& lt;缓存:注解驱动的 ,,,,,缓存管理器=癱acheManager",/比; ,,& lt; !——,配置EhCache的CacheManager 通过configLocation指定ehcache.xml文件的位置,——比; ,,& lt; bean id=癳hCacheManager" ,,,,,类=皁rg.springframework.cache.ehcache.EhCacheManagerFactoryBean" ,,,,,p: configLocation=袄嗦肪?ehcache.xml", p:共享=癴alse",/比; ,,& lt; !——,配置基于EhCache的缓存管理器,并将EhCache的缓存管理器注入该缓存管理器Bean ——比; ,,& lt; bean id=癱acheManager" ,,,,,类=皁rg.springframework.cache.ehcache.EhCacheCacheManager" ,,,,,p: cacheManager-ref=癳hCacheManager"比; ,,& lt;/bean> & lt;/beans>
二,属性文件
& lt; ? xml version=?.0“,编码=癵bk" ?比; & lt; ehcache> & lt;才能diskStore 路径=癹ava.io.tmpdir",/比; ,,& lt; !——,配置默认的缓存区,——比; & lt; defaultCache才能 ,,,maxElementsInMemory=?0000”; 永恒,,,=癴alse" ,,,timeToIdleSeconds=?20”; ,,,timeToLiveSeconds=?20”; ,,,maxElementsOnDisk=?0000000”; ,,,diskExpiryThreadIntervalSeconds=?20”; ,,,memoryStoreEvictionPolicy=癓RU"/比; ,,& lt; !——,配置名为用户的缓存区,——比; & lt;才能cache name=皍sers" ,,,maxElementsInMemory=?0000”; 永恒,,,=癴alse" ,,,overflowToDisk=皌rue" ,,,timeToIdleSeconds=?00”; ,,,timeToLiveSeconds=?00“,/比; & lt;/ehcache>
三,领域模型
package org.crazyit.app.domain; public class 用户 { ,,private String 名称; ,,private int 年龄; ,,public 用户() ,,{} ,,public 用户(名称、String int 年龄) ,,{ ,,,,,超级(); ,,,,,this.name =,名称; ,,,,,this.age =,年龄; ,,} ,,public String  getName () ,,{ ,,,,,return 名称; ,,} ,,public void  setName (String 名称) ,,{ ,,,,,this.name =,名称; ,,} ,,public int  getAge () ,,{ ,,,,,return 年龄; ,,} ,,public void  setAge (int 年龄) ,,{ ,,,,,this.age =,年龄; ,,} }
四、服务
1接口类
package org.crazyit.app.service; import org.crazyit.app.domain.User; public interface  UserService { ,,User getUsersByNameAndAge(名称、String int 年龄); ,,User getAnotherUser(名称、String int 年龄); }
2实现类
package org.crazyit.app.service.impl; import org.crazyit.app.service.UserService; import org.crazyit.app.domain.User; import org.springframework.stereotype.Service; null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null怎么在春天中对类的级别进行缓存