安卓篱笆

  • 400-800-1234
  • 为您定制专业的垂直门户
搜索
猜你喜欢
查看: 11977|回复: 0
打印 上一主题 下一主题
收起左侧

[Java] java web运用@Cacheable配置,屡屡报错

[复制链接]

308

主题

307

帖子

1097

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1097
跳转到指定楼层
楼主
发表于 2018-3-23 06:00:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,,享用更多功能,让你轻松玩转本站。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
[size=1.2]按照网上流程一步步配置spring缓存,运行项目还是报错,什么情况?

第一步:spring-servlet.xml 添加如下声明
  • <!-- 启用缓存注解功能,这个是必须的,否则注解不会生效,另外,该注解一定要声明在spring主配置文件中才会生效 -->
  •     <cache:annotation-driven cache-manager="cacheManager" />
  •     <!-- cacheManager工厂类,指定ehcache.xml的位置 -->
  •     <bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
  •         <property name="configLocation"  value="classpath:cache/ehcache.xml"/>
  •     </bean>
  •     <!-- 声明cacheManager -->
  •     <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
  •         <property name="cacheManager" ref="cacheManagerFactory"/>
  •     </bean>
第二步:创建 ehcache.xml
  • <span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8"?>
  • <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  •     xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
  •     updateCheck="false" dynamicConfig="false" monitoring="autodetect">
  •     <diskStore path="java.io.tmpdir" />
  •     <!--
  •         diskStore path:用来配置磁盘缓存使用的物理路径
  •         name:   缓存名称,cache的唯一标识(ehcache会把这个cache放到HashMap里)
  •         eternal="false"   元素是否永恒,如果是就永不过期(必须设置)
  •         maxElementsOnDisk====磁盘缓存中最多可以存放的元素数量,0表示无穷大
  •         maxElementsInMemory="1000" 内存缓存中最多可以存放的元素数量(必须设置)
  •         timeToIdleSeconds="0"   导致元素过期的访问间隔(秒为单位). 0表示可以永远空闲,默认为0
  •         timeToLiveSeconds="600" 元素在缓存里存在的时间(秒为单位). 0 表示永远存在不过期
  •         overflowToDisk="false"  当缓存达到maxElementsInMemory值是,是否允许溢出到磁盘(必须设置)
  •         diskPersistent="false"  磁盘缓存在VM重新启动时是否保持(默认为false)
  •         diskExpiryThreadIntervalSeconds="100" 磁盘失效线程运行时间间隔,默认是120秒
  •         memoryStoreEvictionPolicy="LFU" 内存存储与释放策略.当达到maxElementsInMemory时
  •                共有三种策略,分别为LRU(最近最少使用)、LFU(最常用的)、FIFO(先进先出)默认使用"最近使用"策略
  •     -->
  •     <defaultCache
  •         eternal="false"
  •         maxElementsInMemory="3000"
  •         timeToIdleSeconds="3600"
  •         timeToLiveSeconds="0"
  •         overflowToDisk="true"
  •         diskPersistent="false"
  •         diskExpiryThreadIntervalSeconds="100"
  •         memoryStoreEvictionPolicy="LRU"/>
  •     <cache name="propConfigCache"
  •         eternal="false"
  •         maxElementsInMemory="3000"
  •         overflowToDisk="true"
  •         timeToIdleSeconds="0"
  •         timeToLiveSeconds="1440"
  •         memoryStoreEvictionPolicy="LFU"/>
  •     <cache name="workTimeCache"
  •         eternal="false"
  •         maxElementsInMemory="3000"
  •         overflowToDisk="true"
  •         timeToIdleSeconds="0"
  •         timeToLiveSeconds="1440"
  •         memoryStoreEvictionPolicy="LFU"/>
  •     <cache name="threeInOneCache"
  •         eternal="false"
  •         maxElementsInMemory="3000"
  •         overflowToDisk="true"
  •         timeToIdleSeconds="0"
  •         timeToLiveSeconds="1440"
  •         memoryStoreEvictionPolicy="LFU"/>
  •     <cache name="transferCache"
  •         eternal="false"
  •         maxElementsInMemory="1000"
  •         overflowToDisk="true"
  •         timeToIdleSeconds="0"
  •         timeToLiveSeconds="1440"
  •         memoryStoreEvictionPolicy="LFU"/>
  •     <cache name="threeInOneFavCache"
  •         eternal="false"
  •         maxElementsInMemory="3000"
  •         overflowToDisk="true"
  •         timeToIdleSeconds="0"
  •         timeToLiveSeconds="1440"
  •         memoryStoreEvictionPolicy="LFU"/>
  •     <cache name="reserveTimeCache"
  •         eternal="false"
  •         maxElementsInMemory="3000"
  •         overflowToDisk="true"
  •         timeToIdleSeconds="0"
  •         timeToLiveSeconds="1440"
  •         memoryStoreEvictionPolicy="LFU"/>
  •     <cache name="mqServerNameCache"
  •         eternal="false"
  •         maxElementsInMemory="3000"
  •         overflowToDisk="true"
  •         timeToIdleSeconds="0"
  •         timeToLiveSeconds="1440"
  •         memoryStoreEvictionPolicy="LFU"/>
  •     <cache name="schWorkTimeCache"
  •         eternal="false"
  •         maxElementsInMemory="3000"
  •         overflowToDisk="true"
  •         timeToIdleSeconds="0"
  •         timeToLiveSeconds="1440"
  •         memoryStoreEvictionPolicy="LFU"/>
  • </ehcache></span>
但是运行项目还是报错:信息如下
Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
翻译:
在同一个虚拟机已经存在另一个未命名的缓存管理器。请提供每个CacheManager独特的名字在配置或做下列:
1。用一个CacheManager。create()静态工厂方法来重用相同的缓存管理器具有相同的名称或创建一个必要的
2。关机前早CacheManager相同名字的创造新的一。
可是我没有在哪里创建过CacheManager啊~~~~

更新:
看网上解决方案是加一句:<property name="shared" value="true"/>
但是我加了后 shared报红,说明没有这个属性。

                               
登录/注册后可看大图




回复

使用道具 举报

*滑动验证:
使用 高级模式(可批量传图、插入视频等)
您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /3 下一条

快速回复 返回顶部 返回列表