spring Cache 配置和调用过程

5 篇文章 0 订阅

在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即可




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值