springmvc+redis缓存问题(添加@Cacheable无效问题)
来源:互联网 发布:农业科技网络书屋网站 编辑:程序博客网 时间:2024/06/07 20:46
搭建时,遇到@Cacheable等注释无效,未将数据存入redis中,现将问题记录下解决方案:
主要的相关配置如下:
在applicationContext.xml中配置了redis相关配置,
<!-- 启用缓存注解功能,这个是必须的,否则注解不会生效,另外,该注解一定要声明在spring主配置文件中才会生效 -->
<cache:annotation-driven />
<context:property-placeholder location="classpath:config/redis.properties"/>
<!-- jedis 配置 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<!--<property name="maxWaitMillis" value="${redis.maxWait}" />-->
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<!-- redis服务器中心 -->
<bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="poolConfig" ref="poolConfig" />
<property name="port" value="${redis.port}" />
<property name="hostName" value="${redis.hostname}" />
<!-- <property name="password" value="${redis.password}" /> -->
<property name="timeout" value="${redis.timeout}"></property>
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="keySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="valueSerializer">
<bean
class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
</property>
</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"></property>
</bean>
<bean class="com.hjc.util.RedisCache">
<property name="redisTemplate" ref="redisTemplate" />
<property name="name" value="data"/>
<!-- common名称要在类或方法的注解中使用 -->
</bean>
</set>
</property>
</bean>
在spring-Servlet.xml中配置:
<mvc:default-servlet-handler/>
<mvc:annotation-driven />
<context:component-scan base-package="com.hjc.*" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
解决办法:
将applicationContext.xml中
<!-- 启用缓存注解功能,这个是必须的,否则注解不会生效,另外,该注解一定要声明在spring主配置文件中才会生效 -->
<cache:annotation-driven />
<context:component-scan base-package="com.hjc.*" />
- springmvc+redis缓存问题(添加@Cacheable无效问题)
- Spring项目中添加Redis服务与缓存同步问题
- Spring项目中添加Redis服务与缓存同步问题
- Redis缓存问题
- Redis与spring整合缓存的业务场景使用方法二(使用注解@Cacheable@CacheEvict)
- java springMVC 图片缓存问题
- 【异常】SSM+Redis缓存@Cacheable之java.lang.ClassCastException等
- 使用spring自带的Cacheable注解处理Redis缓存
- Spring+SpringMvc解决事务无效问题
- 关于SpringMVC中表单验证无效问题
- Spring Cacheable标签 内部调用失效问题
- Spring Cacheable标签 内部调用失效问题
- 解决Animation 添加AnimationClip 无效的问题
- JQ动态添加函数,函数无效问题
- SpringMVC + redis缓存
- Spring-Redis Cacheable中文翻译
- redis缓存机制 保证数据一致性问题
- redis添加缓存
- 原型(补充)
- Java枚举使用详解
- 20170809.XXX系统设计讨论会总结
- Java类加载过程
- 双栈排序
- springmvc+redis缓存问题(添加@Cacheable无效问题)
- POJ 1741 Tree (男人八题
- 【寒江雪】C++四种类型转换
- Groovy语法之操作符
- treap的合并
- 自己定义的下拉多选的链表匡
- Spring Boot AOP代理
- 从九寨沟地震 看那些年数据中心受到的伤害
- 关于easyui datagrid 中日期显示问题