首页 > 编程语言 > 详细

基于xml配置的spring cache

时间:2019-09-18 09:42:19      阅读:135      评论:0      收藏:0      [点我收藏+]

首先,在web.xml中加载配置文件

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath*:**/spring-session.xml,
            classpath*:**/spring-cache.xml,
            classpath*:**/spring-security.xml
        </param-value>
    </context-param>    

然后配置缓存管理器,开启注解支持等

<?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:p="http://www.springframework.org/schema/p"
       xmlns:cache="http://www.springframework.org/schema/cache"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/cache
        http://www.springframework.org/schema/cache/spring-cache.xsd">
    <!-- 支持缓存注解 -->
    <cache:annotation-driven/>

    <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
        <property name="caches">
            <set>
                <bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="default"/>
                <bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="hisCache"/>
            </set>
        </property>
    </bean>

</beans>

然后在相应方法上添加@Cacheable、@CachePut、@CacheEvict等注解

基于xml配置的spring cache

原文:https://www.cnblogs.com/qiushuiblog/p/11539557.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!