spring Cache 配置和调用过程
在spring的配置中添加如下配置:主要有:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-4.1.xsd
">
<!-- **自动代理功能 -->
<aop:aspectj-autoproxy proxy-target-class="true" />
<!-- 加载配置文件 -->
<context:property-placeholder location="classpath:redis.properties"
ignore-unresolvable="true" />
<context:property-placeholder location="classpath*:config.properties"
ignore-unresolvable="true" />
<bean id="LogAspect" class="com.supermap.realestate.organization.aspect.LogAspect"></bean>
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean">
<property name="name" value="default"/>
</bean>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean">
<property name="name" value="accountCache"/>
</bean>
</set>
</property>
</bean>
<!-- 扫描service自动注入为bean -->
<context:component-scan base-package="com.supermap.**.service.**" />
<context:component-scan base-package="com.supermap.**.core.**" />
<context:component-scan base-package="com.supermap.**.realm.**" />
<context:component-scan base-package="com.supermap.**.dao.**" />
<context:component-scan base-package="com.supermap.**.multidao.**" />
<context:component-scan base-package="com.supermap.realestate.mongo.**" />
<context:component-scan base-package="com.supermap.**.annoation.**" />
<context:component-scan base-package="com.supermap.**.aspect.**" />
<context:component-scan base-package="com.supermap.file" />
<bean id="springContext"
class="com.supermap.realestate.organization.core.SuperSpringContext"></bean>
<bean id="ProdefVersonMessage"
class="com.supermap.realestate.workflow.core.ProdefVersonMessage"></bean>
<bean class="com.supermap.realestate.tenant.listener.ConfigLisener" />
<cache:annotation-driven />
</beans>
第二部:在对应的service的方法中添加@Cacheable即可