Using BOTH spymemcached-provider and aws-elasticache-provider simultaneously

13 views
Skip to first unread message

Jerry Collings

unread,
Dec 7, 2017, 4:51:58 PM12/7/17
to simple-spring-memecached
Is there a way to use BOTH the spymemcached provider AND the elasticache provider at the same time?

<dependency>
<groupId>com.google.code.simple-spring-memcached</groupId>
<artifactId>spring-cache</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>com.google.code.simple-spring-memcached</groupId>
<artifactId>spymemcached-provider</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>com.google.code.simple-spring-memcached</groupId>
<artifactId>aws-elasticache-provider</artifactId>
<version>3.6.1</version>
</dependency>

It seems that it will not work because the elasticache provider has its own version of ConnectionFactoryBuilder that it uses to set up dynamic discovery.
Both the ConnectionFactoryBuilder from spymemcached and elasticache use the same package namespace.
When both providers are included as a dependency they conflict and java finds the spymemcached first and produces a NoSuchMethodError when calling setClientMode.

My use case for needing both is that when my code is running in a local data center we use memcached, but when it is running in AWS then we want to use elasticache with dynamic discovery.
My app is a spring boot app and so both jar files are packaged in the uber-jar.
I use @Profile annotations to either include or exclude the appropriate beans based on the spring active profiles.

Is there maybe another way to approach this?

Jakub Białek

unread,
Dec 11, 2017, 12:48:37 AM12/11/17
to simple-spring-memecached
If there is class name collision then there is nothing that we can do in SSM to solve it as this is how Java works. 
There are some workarounds for you but not related to SSM directly:
  1. Change spymemcached to xmemcached, then only one net.spy.ConnectionFactoryBuilder will be available 
  2. Use maven profiles to build two archives one for local data center (it will include spymemcached dependency) and one for production (with aws-elasticache), it should work together with spring profiles if SSM is configured using XML

-- Ragnor




--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.
To post to this group, send email to simple-spring-memecached@googlegroups.com.
Visit this group at https://groups.google.com/group/simple-spring-memecached.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages