我正忙着关注Heroku的Java Memcached教程:https://devcenter.heroku.com/articles/memcache#using-spymemcached-with-spring
我已经通过自制程序安装了Memcached,启动并运行,添加了Spymemcached依赖项并将XML配置添加到我的应用程序上下文中。
问题是我没有得到关于MEMCACHE_USERNAME和MEMCACHE_PASSWORD环境变量需要什么的最微弱的线索,因为当我的应用程序上下文在本地启动时我得到以下身份验证失败:
2013-04-21 18:22:52.108 INFO net.spy.memcached.MemcachedConnection: Added {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2013-04-21 18:22:52.127 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@228ef305
2013-04-21 18:22:52.283 WARN net.spy.memcached.auth.AuthThread: Authentication failed to localhost/127.0.0.1:11211
2013-04-21 18:22:52.398 WARN net.spy.memcached.auth.AuthThread: Authentication failed to localhost/127.0.0.1:11211
2013-04-21 18:22:52.520 WARN net.spy.memcached.auth.AuthThread: Authentication failed to localhost/127.0.0.1:11211 ...
提供用户名和密码的配置:
<bean id="plainCallbackHandler" class="net.spy.memcached.auth.PlainCallbackHandler">
<constructor-arg index="0" value="${MEMCACHE_USERNAME}"/>
<constructor-arg index="1" value="${MEMCACHE_PASSWORD}"/>
</bean>
我必须错过一些相当明显的东西......任何指针?
答案 0 :(得分:0)
如果您在本地运行该应用,则MEMCACHE_USERNAME
和MEMCACHE_PASSWORD
都应为空(除非您在安装期间设置它们)。如果您的配置不处理空值,则可以使用前缀MEMCACHE_USERNAME= MEMCACHE_PASSWORD= the-command-to-run-your-app
运行您的应用程序。
如果您使用Memcache插件在Heroku上运行,您将获得MEMCACHE_USERNAME
,MEMCACHE_PASSWORD
和MEMCACHE_SERVERS
等环境变量,这些变量在您安装添加时自动设置上。
如果您自行托管Memcached服务器,则必须(或 )设置您将在应用程序中配置的SASL用户名和密码。
答案 1 :(得分:0)
HI,我也遇到了类似的问题,因为我没有设置SASL用户名和密码,所以当我删除配置时,错误消息就消失了。
<bean name="defaultCache" class="com.google.code.ssm.CacheFactory">
<property name="cacheName" value="default" />
<property name="cacheClientFactory">
<bean name="cacheClientFactory"
class="com.google.code.ssm.providers.spymemcached.MemcacheClientFactoryImpl" />
</property>
<property name="addressProvider" ref="addressProvider" />
<property name="configuration" ref="cacheFactoryConf" />
</bean>
<bean id="addressProvider" class="com.google.code.ssm.config.DefaultAddressProvider">
<property name="address" value="${memcached.hosts}" />
</bean>
<bean id="cacheFactoryConf"
class="com.google.code.ssm.providers.spymemcached.SpymemcachedConfiguration">
<property name="consistentHashing" value="true" />
<property name="useBinaryProtocol" value="true" />
<property name="keyPrefixSeparator" value=".xxx." />
<property name="useNameAsKeyPrefix" value="true" />
<!--
<property name="authDescriptor">
<bean class="net.spy.memcached.auth.AuthDescriptor">
<constructor-arg index="0">
<value>PLAIN</value>
</constructor-arg>
<constructor-arg index="1">
<bean class="net.spy.memcached.auth.PlainCallbackHandler">
<constructor-arg index="0">
<value>${memcached.username}</value>
</constructor-arg>
<constructor-arg index="1">
<value>${memcached.password}</value>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
</property>
-->
</bean>