问题描述
自己做了一个springMVC+memcached的示例,启动的时候抛了这个错误 [ERROR] attempting to get SockIO from uninitialized pool!memcachedPool可能有点问题,请大家帮忙看下,谢谢了。备注:查了很多资料,咱们iteye中有人遇到过相同的问题,我按照他解决的办法并没有起作用。 pengmj 给出的解决办法是在 <bean id="memcahedPool"中加入lazy-init= false,也不行。大家帮看下我的代码哪里有问题~先谢过哈 spring配置文件如下: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"><bean id="memcachedPool" class="com.danga.MemCached.SockIOPool" factory-method="getInstance" init-method="initialize" lazy-init="false" destroy-method="shutDown"><constructor-arg><value>memcachedPool</value></constructor-arg><property name="servers"><list><value>127.0.0.1:11211</value></list></property><property name="initConn"><value>20</value></property><property name="minConn"><value>20</value></property><property name="maxConn"><value>1000</value></property><property name="nagle"><value>false</value></property><property name="socketTO"><value>3000</value></property></bean><bean id="memcachedClient" class="com.danga.MemCached.MemCachedClient" ><constructor-arg><value>memcachedPool</value></constructor-arg></bean></beans> 使用了基于注解的方式,Controller类如下 package com.test.web;import java.util.Date;import javax.servlet.http.HttpSession;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.servlet.ModelAndView;import com.danga.MemCached.MemCachedClient;import com.test.utils.MemcachedUtils;@Controller@RequestMapping("/loginController")public class Login {@Autowiredprivate MemCachedClient mcc;@RequestMapping("/login")public ModelAndView login(@RequestParam(value = "username") String userid,@RequestParam(value = "password") String passwd, HttpSession session){ModelAndView m = new ModelAndView();m.setViewName("../index");MemcachedUtils.set("test", "hello memcached",new Date(1000 * 60));//这里有问题!Object o = MemcachedUtils.get("test");//这里有问题!System.out.println(o.toString());m.addObject("errMsg","成功返回!");return m;}} MemcachedUtils类代码如下: import java.io.IOException;import java.io.PrintWriter;import java.io.StringWriter;import java.lang.management.ManagementFactory;import java.lang.management.RuntimeMXBean;import java.text.SimpleDateFormat;import java.util.Date;import org.apache.log4j.Logger;import com.danga.MemCached.MemCachedClient;public class MemcachedUtils {private static final Logger logger = Logger.getLogger(MemcachedUtils.class); private static MemCachedClient cachedClient; static { if (cachedClient == null) cachedClient = new MemCachedClient(); } private MemcachedUtils() { } /** * 添加memcached。 */ public static boolean set(String key, Object value, Date expire) { return setExp(key, value, expire); } private static boolean setExp(String key, Object value, Date expire) { boolean flag = false; try { flag = cachedClient.set(key, value, expire); } catch (Exception e) { logger.error(""Memcached set方法报错,key值:" + key + "rn"", e); } return flag; } /** * 获取memcached。 */ public static Object get(String key) { Object obj = null; try { obj = cachedClient.get(key); } catch (Exception e) { logger.error(""Memcached get方法报错,key值:" + key + "rn"", e); } return obj; } } 执行login类的login方法时出现[ERROR] attempting to get SockIO from uninitialized pool!大家帮看看,先谢过了哈。 错误堆栈信息如下:[ERROR] attempting to get SockIO from uninitialized pool![ERROR] attempting to get SockIO from uninitialized pool!2014-11-27 23:39:45 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() for servlet springMVC threw exceptionjava.lang.NullPointerExceptionat com.test.web.Login.login(Login.java:37)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)at java.lang.reflect.Method.invoke(Unknown Source)at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)at java.lang.Thread.run(Unknown Source)
解决方案
使用的什么客户端,xmemcached和spring的整合:http://silentwu.iteye.com/blog/2124413