gpt4 book ai didi

java - Spring许多mamcached实现

转载 作者:行者123 更新时间:2023-12-01 13:37:06 26 4
gpt4 key购买 nike

我需要在我的应用程序中使用一些 memcached 服务器。

到目前为止,我只使用一种配置:

<bean id="memcachedClient" class="net.spy.memcached.spring.MemcachedClientFactoryBean" scope="singleton">
<property name="servers" value="${app.memcached.url}"/>
<property name="protocol" value="BINARY"/>
<property name="transcoder">
<bean class="net.spy.memcached.transcoders.SerializingTranscoder">
<property name="compressionThreshold" value="1024"/>
</bean>
</property>
<property name="opTimeout" value="1000"/>
<property name="timeoutExceptionThreshold" value="1998"/>
<property name="locatorType" value="CONSISTENT"/>
<property name="failureMode" value="Redistribute"/>
<property name="useNagleAlgorithm" value="false"/>
</bean>

当我想使用两台服务器时,只需添加:

<bean id="memcachedClient" class="net.spy.memcached.spring.MemcachedClientFactoryBean" scope="singleton">
<property name="servers" value="${app.memcached.url}"/>
<property name="protocol" value="BINARY"/>
<property name="transcoder">
<bean class="net.spy.memcached.transcoders.SerializingTranscoder">
<property name="compressionThreshold" value="1024"/>
</bean>
</property>
<property name="opTimeout" value="1000"/>
<property name="timeoutExceptionThreshold" value="1998"/>
<property name="locatorType" value="CONSISTENT"/>
<property name="failureMode" value="Redistribute"/>
<property name="useNagleAlgorithm" value="false"/>
</bean>

<bean id="memcachedAs" class="net.spy.memcached.spring.MemcachedClientFactoryBean" scope="singleton">
<property name="servers" value="${app.memcached.url.as}"/>
<property name="protocol" value="BINARY"/>
<property name="transcoder">
<bean class="net.spy.memcached.transcoders.SerializingTranscoder">
<property name="compressionThreshold" value="1024"/>
</bean>
</property>
<property name="opTimeout" value="1000"/>
<property name="timeoutExceptionThreshold" value="1998"/>
<property name="locatorType" value="CONSISTENT"/>
<property name="failureMode" value="Redistribute"/>
<property name="useNagleAlgorithm" value="false"/>
</bean>

但后来我收到错误:

is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [net.spy.memcached.MemcachedClient] is defined: expected single matching bean but found 

你能帮我,如何实现许多配置吗?

最佳答案

我假设你有一个像这样的注入(inject)目标

@Autowired
private MemcachedClient client;

Spring 将尝试根据 bean 的类型来解析它。但是您的上下文中有两个该类型的 bean,因此 Spring 不知道选择哪一个。相反,您可以通过 ID 注入(inject) bean

@Resource(name="memcachedAs")
private MemcachedClient client;

甚至

@Autowired 
@Qualifier("memcachedAs")
private MemcachedClient client;

关于java - Spring许多mamcached实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21189470/

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