Reputation: 2177
I need to user few memcached servers in my application.
Till now i was using only one configuration:
<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>
And when i want to use two servers, a just wanted do add:
<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>
But then i get error:
is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [net.spy.memcached.MemcachedClient] is defined: expected single matching bean but found
Can you help me, how to implement many configurations ?
Upvotes: 0
Views: 1229
Reputation: 279970
I'm assuming you have an injection target like
@Autowired
private MemcachedClient client;
Spring will try to resolve the bean by its type. But you have two beans of that type in your context so Spring doesn't know which one to choose. Instead, you could inject the bean by ID
@Resource(name="memcachedAs")
private MemcachedClient client;
or even
@Autowired
@Qualifier("memcachedAs")
private MemcachedClient client;
Upvotes: 1