大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
配置redis.clients.jedis.JedisPool时报错如下:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jedisPool’ defined in class path resource [beans.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:445)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:419)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:544)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:304)
… 42 more
使用的是jedis-2.9.0.jar,原因:
<bean id="jedisPool" class="redis.clients.jedis.JedisPool" destroy-method="destroy"
depends-on="poolCfg">
<constructor-arg name="poolConfig" ref="poolCfg" />
<constructor-arg name="host" value="${redis.host}" />
<constructor-arg name="port" value="${redis.port}"/>
<constructor-arg name="password" value="${redis.pass}"/>
<constructor-arg name="database" value="${redis.database}"/>
<!--<constructor-arg name="timeout" value="${redis.timeout}"/> 连接超时 -->
</bean>
查看JedisPool的源码,可以发现它有N多个重载的构造函数:
而找了个遍,就是没有我配置里面写的poolConfig,host,port,password,database的,再加个timeout的倒是有,那就多加个timeout吧,也不知道怎么这么有运气,正好碰到了没有的构造函数,所以在spring中配置JedisPool之前最好还是去看下这个类的结构,找一个适合自己的构造函数去配置就行了,我修改之后的配置如下:
<bean id="jedisPool" class="redis.clients.jedis.JedisPool" destroy-method="destroy"
depends-on="poolCfg">
<constructor-arg name="poolConfig" ref="poolCfg" />
<constructor-arg name="host" value="${redis.host}" />
<constructor-arg name="port" value="${redis.port}"/>
<constructor-arg name="password" value="#{'${redis.pass}'!=''?'${redis.pass}':null}"/>
<constructor-arg name="database" value="#{'${redis.database}'!=''?'${redis.database}':0}"/>
<constructor-arg name="timeout" value="${redis.timeout}"/>
</bean>
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/197124.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...