gpt4 book ai didi

java - 尝试连接 Lettuce 连接工厂时出错

转载 作者:行者123 更新时间:2023-11-30 03:40:33 26 4
gpt4 key购买 nike

我正在尝试使用 Spring Data Redis(版本:1.1.x)为我的 Redis 客户端(生菜客户端版本:2.3.3)设置一个连接工厂,但在将所有内容连接在一起时遇到了一些麻烦。

这是我的配置:application-context-redis.xml

<bean id="lettuceConnectionFactory"
class="org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory">
<constructor-arg index="0" ref="redisPool"/>
</bean>

<bean id="redisPool"
class="org.springframework.data.redis.connection.lettuce.DefaultLettucePool">
<constructor-arg index="0" value="${redis.host}" />
<constructor-arg index="1" value="${redis.port}"/>
<constructor-arg index="2" ref="#{redisPoolConfig.Config}"/>
</bean>

<bean id="redisPoolConfig" class="org.apache.commons.pool.impl.GenericObjectPool"
p:maxActive="${redis.maxActive}"
p:maxIdle="${redis.maxIdle}"
p:minIdle="${redis.minIdle}"
p:maxWait="${redis.maxWait}"
p:testOnBorrow="${redis.testOnBorrow}"
p:testOnReturn="${redis.testOnReturn}"
p:testWhileIdle="${redis.testWhileIdle}"
p:whenExhaustedAction="${redis.whenExhaustedAction}"
p:timeBetweenEvictionRunsMillis="${redis.timeBetweenEvictionRunsMillis}"
p:numTestsPerEvictionRun="${redis.numTestsPerEvictionRun}"
p:softMinEvictableIdleTimeMillis="${redis.softMinEvictableIdleTimeMillis}"
p:minEvictableIdleTimeMillis="${redis.minEvictableIdleTimeMillis}"/>
/>

<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
p:connectionFactory-ref="lettuceConnectionFactory"/>

这是 redisPool bean 的构造函数签名:

public DefaultLettucePool(String hostName, int port, Config poolConfig) {
this.hostName = hostName;
this.port = port;
this.poolConfig = poolConfig;
}

poolConfig 属性是一个公共(public)内部静态类:org.apache.commons.pool.impl.GenericObjectPool.Config

由于配置属性is a static inner class (see here)并且不包含 getter 方法,我很难尝试将其注入(inject)到 redisPool bean 中。

这是我收到的错误:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisPool' defined in class path resource [application-context-redis.xml]: Cannot resolve reference to bean '#{redisPoolConfig.Config}' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 16): Field or property 'Config' cannot be found on object of type 'org.apache.commons.pool.impl.GenericObjectPool'
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:615)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1045)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:949)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
... 72 more
Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 16): Field or property 'Config' cannot be found on object of type 'org.apache.commons.pool.impl.GenericObjectPool'
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:142)
at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1312)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:225)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:312)
... 84 more

最佳答案

Spring Data Redis 附带了方便的 org.apache.commons.pool.impl.GenericObjectPool.Config 包装器,它基本上可以让您解决您遇到的问题如上所述。

<bean id="lettuceConnectionFactory "
class="org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory">
<constructor-arg index="0" ref="lettucePool" />
</bean>

<bean id="lettucePool" class="org.springframework.data.redis.connection.lettuce.DefaultLettucePool">
<property name="hostName" value="${redis.host}" />
<property name="port" value="${redis.port}" />
<property name="poolConfig" ref="lettucePoolConfiguration" />
</bean>

<bean id="lettucePoolConfiguration" class="org.springframework.data.redis.connection.PoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxActive" val...
</bean>

关于java - 尝试连接 Lettuce 连接工厂时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26893909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com