gpt4 book ai didi

java - 如何在 java web 应用程序中使用 memcached 客户端,特别是在运行在 tomcat 上的 Struts 2 中?

转载 作者:行者123 更新时间:2023-11-28 23:30:10 25 4
gpt4 key购买 nike

public class MemCacheClientInit {
static MemcachedClient mcc = null;
static String ipAdderss = "127.0.0.1";
static int port = 11211;
public static boolean isMemCacheInit = false;

public static MemcachedClient getInstance() {
if (mcc == null) {
try {
isMemCacheInit = initMemServer();
mcc = new MemcachedClient(new InetSocketAddress(ipAdderss, port));
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return mcc;
}

private static boolean initMemServer() {
try {
String[] servers = {"localhost:11211",};
Integer[] weights = {1};
SchoonerSockIOPool pool = SchoonerSockIOPool.getInstance();
pool.setServers(servers);
pool.setWeights(weights);
pool.setInitConn(5);
pool.setMinConn(5);
pool.setMaxConn(250);
pool.setMaxIdle(1000 * 60 * 60 * 6);
pool.initialize();
pool.setHashingAlg(SchoonerSockIOPool.NEW_COMPAT_HASH);
return true;
}

catch (Exception ex) {
return false;
}
}
}

我直接从我的 DAO 运行此代码并在 Memcache 中设置对象,在 InitMemServer 方法的上述代码片段中,同时获取 SchoonerSockIOPool 的实例它正在抛出invocationTarget 异常。

最佳答案

I got the answer it was in the pom.xml
<dependency>
<groupId>spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.8.1</version>
<scope>provided</scope>
</dependency>
I have given scope as provided that should be compile.

关于java - 如何在 java web 应用程序中使用 memcached 客户端,特别是在运行在 tomcat 上的 Struts 2 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31499565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com