配置如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- turn on declarative caching -->
<cache:annotation-driven cache-manager="cacheManager" />
<context:component-scan base-package="com.hello.service">
</context:component-scan>
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="localhost" p:port="6379" p:use-pool="true"/>
<!-- redis template definition -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisConnectionFactory"/>
<!-- declare Redis Cache Manager -->
<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager" c:template-ref="redisTemplate"/>
</beans>
运行启动报如下错误:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'quartzJob': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attendenceService' defined in file [D:\apache-tomcat-6.0.37\webapps\lovebaby3.0\WEB-INF\classes\com\zsabb\service\attendence\AttendenceService.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0': Cannot resolve reference to bean 'cacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cacheManager' defined in class path resource [applicationContext/applicationContext-redis.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.data.redis.core.RedisOperations]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
jar包版本:
使用的redis服务版本是:3.0
spring的core是3.2.8
spring-data-redis是1.6.2
jedis版本是2.5.2;
spring的版本是不能再升了,这因为别人用了其他的mybaties的封装jar,换到spring4会报错;
麻烦大牛帮我解决下,看看
<spanstyle="font-size:13.3333px;">解决了吗 我用spring4.17也有这个错误这个不是spring的问题,真不好意思,我发布此问题后就立马解决了,原因是spring-data-redis的jar的版本问题,1.5.2.RELEASE.jar <beanid="cacheManager"class="org.springframework.data.redis.cache.RedisCacheManager">
<constructor-argindex="0"ref="redisTemplate"></constructor-arg>
</bean>
真不好意思,我发了解决了就没跟进这个问题了<spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><beanid="cacheManager"class="org.springframework.data.redis.cache.RedisCacheManager"c:template-ref="redisTemplate"/>这样写会报这个异常,官方文档也是这样写的,所以调查了很长时间才等到上述的解决方法。还有,别用百度查这样的问题,根本查不到好的解决方案,并且现在国内用spring-data-redis1.7的比较少,资料也比较少,还是用gg或者雅虎日本也可以
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。