Java应用中Memcached认证失败



我正忙着跟随Heroku的Memcached Java教程: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>
我一定是错过了一些相当明显的东西…指针吗?

如果你在本地运行应用程序,MEMCACHE_USERNAMEMEMCACHE_PASSWORD应该都是空白的(除非你在安装过程中设置它们)。如果你的配置不处理空值,你可以用前缀MEMCACHE_USERNAME= MEMCACHE_PASSWORD= the-command-to-run-your-app运行你的应用程序。

如果您在Heroku上运行Memcache插件,您将获得MEMCACHE_USERNAMEMEMCACHE_PASSWORDMEMCACHE_SERVERS等环境变量,它们在您安装插件时自动设置。

如果您自托管Memcached服务器,则必须(或应该)设置将在应用程序中配置的SASL用户名和密码。

你好,我也遇到了类似的问题,因为我没有设置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>

最新更新