开发者

Error in creating Cache in Google Apps Engine. net.sf.jsr107cache.CacheException

开发者 https://www.devze.com 2023-03-11 09:32 出处:网络
I just started to play with MemCache in Google Apps Engine and every time I create CacheFactory I get this error :

I just started to play with MemCache in Google Apps Engine and every time I create CacheFactory I get this error :

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

I'm using Apps Engine SDK "1.5.0.1 - 2011-05-16" ( which is the latest ). I tested this in my local.

Anybody know how to fix this issue?

Here is my snippet of my code.

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

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


This should be fixed in App Engine SDK 1.5.0.1.

Make sure you are importing:

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

I don't have any "Could not find class" error with the following sample code

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());
    }
  }
}


Eclipse projects created with App Engine plugin 1.5.0 had the broken jsr107cache-1.1.jar added to their war/WEB-INF/lib directory.

Updating the SDK and plugin doesn't alter your projects, you'll need to fix that yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消