记录jedisPool注入的jedisPoolConfig的问题

最近在使用redis的时候遇到一个问题,记录一下

jar包版本:

    jedis-2.9.0.jar

    commons-pool2-2.4.3.jar

    spring-*-3.24.jar

<context:property-placeholder ignore-unresolvable="true" location="classpath:redis.properties" />
	  <!-- redis 单机连接方案 -->
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <!--最大连接数 -->
        <property name="maxTotal" value="30"/>
        <!--最大空闲连接数 -->
        <property name="maxIdle" value="10"/>
        <!--每次释放连接的最大数目 -->
        <property name="numTestsPerEvictionRun" value="1024"/>
        <!--释放连接的扫描间隔(单位:毫秒) -->
        <property name="timeBetweenEvictionRunsMillis" value="30000"/>
        <!--连接最小空闲时间(单位:毫秒) -->
        <property name="minEvictableIdleTimeMillis" value="100000"/>
        <!--连接空闲多久后释放,当空闲时间大于该值并且空闲连接大于最大空闲连接时直接释放连接 -->
        <property name="softMinEvictableIdleTimeMillis" value="10000"/>
        <!--获取连接时最大等待毫秒数,如果该值小于0,则阻塞不确定的时长,默认值-1 -->
        <property name="maxWaitMillis" value="1500"/>
        <!--在获取连接时检查连接有效性,默认为false -->
        <property name="testOnBorrow" value="false"/>
        <!--在连接空闲时检查连接有效性,默认为false -->
        <property name="testWhileIdle" value="true"/>
        <!--连接耗尽是否阻塞,false代表抛异常,true代表阻塞直到超时,默认为true -->
        <property name="blockWhenExhausted" value="false"/>
    </bean>

    <bean id = "jedisPool" class="redis.clients.jedis.JedisPool" scope="singleton">
      <constructor-arg index="0" ref="jedisPoolConfig"/>
      <constructor-arg index="1" value="${redis.host}" type="String"/>
      <constructor-arg index="2" value="${redis.port}" type="int"/>
      <!-- <constructor-arg index="3" value="${redis.timeout}" type="int"/> -->
      <!-- <constructor-arg index="4" value="${redis.password}"/> -->
    </bean>

在注入    jedisPoolConfig的时候报错

    

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisPool' defined in class path resource [base/conf/spring/spring-base-redis.xml]: 
Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)

尝试代码注入

redis.clients.jedis.JedisPoolConfig
可以拿到对象(非代理对象?)但是转换的时候报错:

    java.lang.ClassCastException: com.sun.proxy.$Proxy8 cannot be cast to...

问题参考:

http://blog.csdn.net/yinzn2011/article/details/46455973

猜你喜欢

转载自blog.csdn.net/hiqingtian/article/details/79493817