0

我正忙于关注 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>

我一定遗漏了一些相当明显的东西......任何指针?

4

2 回答 2

0

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

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

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

于 2013-04-22T19:19:20.980 回答
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>
于 2016-01-06T09:54:24.313 回答