我的web應用程序使用Resteasy和Infinispan緩存。在JBoss Wildfly下啓用Rest緩存
我們的設置在Jetty中正常工作,但現在我們需要在JBoss Wildfly 8.1.0中進行部署。
在Wildfly我們有一些要求後陣性錯誤:
java.lang.ClassCastException: org.jboss.resteasy.plugins.cache.server.InfinispanCache$CacheEntry cannot be cast to org.jboss.resteasy.plugins.cache.server.InfinispanCache$CacheEntry
at org.jboss.resteasy.plugins.cache.server.InfinispanCache.get(InfinispanCache.java:85)
at org.jboss.resteasy.plugins.cache.server.ServerCacheHitFilter.handleGET(ServerCacheHitFilter.java:53)
at org.jboss.resteasy.plugins.cache.server.ServerCacheHitFilter.filter(ServerCacheHitFilter.java:38)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:256)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:242)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:229)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
注意Widlfly下,我們內部的戰爭打包的唯一依賴是RestEasy的緩存-core.jar添加,其中ServerCacheFeature
所屬的所有其他東西是服務器提供的。在Jetty下,我們需要收拾一切。
以下是我們在Jetty中所做的工作。
一些Rest方法使用註釋org.jboss.resteasy.annotations.cache.Cache。例如:
@GET
@Path("/actions")
@Cache(maxAge = 3600)
@Produces(value = { APPLICATION_XML, APPLICATION_JSON })
public Action[] getActions() {
...
}
要啓用緩存我添加緩存功能,在適用對象:
@Inject
private CacheContainer cacheContainer;
@Override
public Set<Object> getSingletons() {
Set<Object> objects = getDefaultProviders();
Cache<Object, Object> cache = cacheContainer.getCache("rest");
objects.add(new ServerCacheFeature(new InfinispanCache(cache)));
return objects;
}
最後我用CDI,並得到CacheContainer
// There's a cache manager deployed in this JNDI name in standlone.xml/jetty.xml
public static final String CACHE_MANAGER_JNDI_NAME = "java:/application/cachemanager/MyCacheManager";
@Produces
@ApplicationScoped
public CacheContainer createCacheManager() {
return DependencyContext.getFromJndi(CACHE_MANAGER_JNDI_NAME, CacheContainer.class);
}
所以注入org.infinispan.manager.CacheContainer
...什麼是正確的在JBoss Widlfy下使用infinispan啓用和處理Resteasy Cache的方法?
更新:事實上,我有兩場戰爭與緩存相同的部署配置。只有緩存管理器的JNDI名稱不同。