2011-06-07 70 views
0

我刚开始在谷歌应用程序引擎与MEMCACHE玩,每次我创建CacheFactory时间我得到这个错误:在Google Apps引擎中创建缓存时出错。 net.sf.jsr107cache.CacheException

net.sf.jsr107cache.CacheException: 
Could not find class: 'com.google.appengine.api.memcache.jsr107cache.GCacheFactory' 
    at net.sf.jsr107cache.CacheManager.getCacheFactory(CacheManager.java:46) 

我使用的应用程序引擎的SDK“1.5.0.1 - 2011-05-16“(这是最新的)。我在当地测试了这个。

有人知道如何解决这个问题?

这是我的代码片段。

@SuppressWarnings("rawtypes") 
    Map props = new HashMap(); 
    //props.put(GCacheFactory.EXPIRATION_DELTA, 3600); 

    try { 
     CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory(); 
     cache = cacheFactory.createCache(props); 
     if(cache.containsKey("userAgent")) 
     { 
      userAgent = (String)cache.get("userAgent"); 
     }else 
     { 
      cache.put("userAgent", userAgent+" from MEMCache"); 
     } 
    } catch (CacheException e) { 
     e.printStackTrace(); 
    } 

回答

1

这应该固定在App Engine SDK 1.5.0.1

确保您导入:

import net.sf.jsr107cache.CacheException; 
import net.sf.jsr107cache.CacheFactory; 
import net.sf.jsr107cache.CacheManager; 

我没有与下面的示例代码中的任何“找不到类”错误

package classnotfoundtest; 

import net.sf.jsr107cache.CacheException; 
import net.sf.jsr107cache.CacheFactory; 
import net.sf.jsr107cache.CacheManager; 

import java.io.IOException; 
import javax.servlet.http.*; 

@SuppressWarnings("serial") 
public class ClassnotfoundtestServlet extends HttpServlet { 
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { 
    try { 
     CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory(); 
     resp.setContentType("text/plain"); 
     resp.getWriter().println("Hello, world"); 
    } catch (CacheException e) { 
     e.printStackTrace(resp.getWriter()); 
    } 
    } 
} 
与App Engine插件1.5创建
+0

Yap。我已经读过1.5.0.1是为了解决这个问题,但似乎不起作用。我会尽快尝试你的测试类。 – Rudy 2011-06-07 11:44:17

0

Eclipse项目.0已将损坏的jsr107cache-1.1.jar添加到其war/WEB-INF/lib目录中。

更新SDK和插件不会改变您的项目,您需要自行解决。