1

我正在使用 Resteasy 编写 Web 服务层,并尝试将 infinispan 配置为服务器端响应缓存,如下所述:http: //docs.jboss.org/resteasy/docs/3.0.1.Final/userguide/html_single /index.html#server_cache

因为这一层是无状态的,并且可能部署在 heroku 上的多个节点上,所以我想使用 mongodb 缓存加载器来存储缓存数据。这样,缓存将在所有节点之间同步。

但是,在本地计算机上启动服务器时,出现以下错误:

org.infinispan.CacheException:无法启动缓存加载器(此消息末尾的完整堆栈跟踪)

这是我声明的依赖项:

compile 'org.jboss.resteasy:resteasy-jaxrs:3.0.1.Final'
compile 'org.jboss.resteasy:resteasy-client:3.0.1.Final'
compile 'org.jboss.resteasy:resteasy-spring:3.0.1.Final'
compile 'org.jboss.resteasy:resteasy-cache-core:3.0.1.Final'
compile 'org.infinispan:infinispan-cachestore-mongodb:5.3.0.Final'

(奇怪的是 org.infinispan:infinispan-cachestore-mongodb:5.3.0.Final jar 几乎包含了 org.jboss.resteasy:resteasy-cache-core:3.0.1.Final 中也存在的所有类。我想知道是否这就是导致问题的原因。我在依赖图上玩了很多,试图排除重复项,直到我用相关的类构建了我自己的 mongo 缓存加载器 jar,但是这样做或删除核心 jar 并只留下mongo 缓存加载器 jar 抛出异常,例如 Unexpected element '{urn:infinispan:config:5.3}infinispan' )

我还按照网站上的文档配置了 infinispan.xml:https ://docs.jboss.org/author/display/ISPN/Cache+Loaders+and+Stores#CacheLoadersandStores-MongoDBcacheloader

<?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="urn:infinispan:config:5.3
                              http://www.infinispan.org/schemas/infinispan-config-5.3.xsd
                              urn:infinispan:config:mongodb:5.3
                              https://raw.github.com/infinispan/infinispan/5.3.x/cachestore/mongodb/src/main/resources/schema/mongodb-cachestore-config-5.3.xsd"
 xmlns="urn:infinispan:config:5.3">

     <namedCache name="nf-demo">
          <eviction strategy="LIRS" maxEntries="10" />
               <loaders>
                    <mongodbStore xmlns="urn:infinispan:config:mongodb:5.3">
                         <connection host="localhost" port="27017" timeout="2000"
                              acknowledgment="0" />
                         <storage database="infinispan_test_database" collection="infispan_cachestore" />
                    </mongodbStore>
               </loaders>
     </namedCache>
</infinispan>

我不确定是否是导致问题的版本冲突,或者是否是 mongodb 缓存 laoder 上的错误。我也不确定是否需要执行额外的步骤来在 infospan 配置中注册 mongo db 加载器。在另一个线程上,有人在创建自定义加载器时遇到了同样的错误,因为他没有实现 CacheLoaderConfig.getCacheLoaderClassName()。我在 github 中对 mongo db loader 源代码大惊小怪,但找不到对这个方法的任何引用。这是供参考的线程:https ://community.jboss.org/thread/218305

任何帮助,将不胜感激。如果您需要更多信息,请告诉我。

完整的堆栈跟踪:

Failed startup of context org.gradle.api.plugins.jetty.internal.JettyPluginWebAppContext@6823bf90{/avivoca,/Users/daniel.freitas/dev/projects/mtl-lp-notification-layer/src/main/webapp}
org.infinispan.CacheException: Unable to invoke method public void org.infinispan.loaders.CacheLoaderManagerImpl.start() on object of type CacheLoaderManagerImpl
          at org.infinispan.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.java:207)
          at org.infinispan.factories.AbstractComponentRegistry$PrioritizedMethod.invoke(AbstractComponentRegistry.java:889)
          at org.infinispan.factories.AbstractComponentRegistry.invokeStartMethods(AbstractComponentRegistry.java:658)
          at org.infinispan.factories.AbstractComponentRegistry.internalStart(AbstractComponentRegistry.java:647)
          at org.infinispan.factories.AbstractComponentRegistry.start(AbstractComponentRegistry.java:550)
          at org.infinispan.factories.ComponentRegistry.start(ComponentRegistry.java:221)
          at org.infinispan.CacheImpl.start(CacheImpl.java:691)
          at org.infinispan.manager.DefaultCacheManager.wireAndStartCache(DefaultCacheManager.java:685)
          at org.infinispan.manager.DefaultCacheManager.createCache(DefaultCacheManager.java:648)
          at org.infinispan.manager.DefaultCacheManager.getCache(DefaultCacheManager.java:544)
          at org.jboss.resteasy.plugins.cache.server.ServerCacheFeature.getXmlCache(ServerCacheFeature.java:88)
          at org.jboss.resteasy.plugins.cache.server.ServerCacheFeature.getCache(ServerCacheFeature.java:61)
          at org.jboss.resteasy.plugins.cache.server.ServerCacheFeature.configure(ServerCacheFeature.java:36)
          at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1673)
          at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1310)
          at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1232)
          at org.jboss.resteasy.spi.ResteasyDeployment.registerProvider(ResteasyDeployment.java:531)
          at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:346)
          at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:241)
          at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28)
          at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
          at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
          at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1272)
          at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
          at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:489)
          at org.gradle.api.plugins.jetty.internal.JettyPluginWebAppContext.doStart(JettyPluginWebAppContext.java:112)
          at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
          at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
          at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
          at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
          at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
          at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
          at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
          at org.mortbay.jetty.Server.doStart(Server.java:224)
          at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
          at org.gradle.api.plugins.jetty.internal.Jetty6PluginServer.start(Jetty6PluginServer.java:111)
          at org.gradle.api.plugins.jetty.AbstractJettyRunTask.startJettyInternal(AbstractJettyRunTask.java:247)
          at org.gradle.api.plugins.jetty.AbstractJettyRunTask.startJetty(AbstractJettyRunTask.java:198)
          at org.gradle.api.plugins.jetty.AbstractJettyRunTask.start(AbstractJettyRunTask.java:169)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:601)
          at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
          at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
          at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047)
          at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877)
          at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216)
          at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122)
          at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
          at org.gradle.api.plugins.jetty.JettyRun_Decorated.invokeMethod(Unknown Source)
          at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
          at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
          at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:217)
          at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
          at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:199)
          at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:526)
          at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:509)
          at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
          at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
          at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
          at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
          at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter$1.run(CacheLockReleasingTaskExecuter.java:35)
          at org.gradle.internal.Factories$1.create(Factories.java:22)
          at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:179)
          at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:232)
          at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
          at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
          at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter.execute(CacheLockReleasingTaskExecuter.java:33)
          at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:58)
          at org.gradle.api.internal.tasks.execution.ContextualisingTaskExecuter.execute(ContextualisingTaskExecuter.java:34)
          at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter$1.run(CacheLockAcquiringTaskExecuter.java:39)
          at org.gradle.internal.Factories$1.create(Factories.java:22)
          at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
          at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112)
          at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
          at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
          at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter.execute(CacheLockAcquiringTaskExecuter.java:37)
          at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
          at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
          at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
          at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)
          at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)
          at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:282)
          at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.executeTask(DefaultTaskPlanExecutor.java:48)
          at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.processTask(DefaultTaskPlanExecutor.java:34)
          at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:27)
          at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89)
          at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
          at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
          at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
          at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
          at org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
          at org.gradle.internal.Factories$1.create(Factories.java:22)
          at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
          at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112)
          at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
          at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
          at org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
          at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
          at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
          at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
          at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
          at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
          at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
          at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
          at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
          at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
          at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
          at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
          at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
          at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
          at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
          at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
          at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
          at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
          at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
          at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
          at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
          at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
          at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
          at org.gradle.launcher.Main.doAction(Main.java:48)
          at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
          at org.gradle.launcher.Main.main(Main.java:39)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:601)
          at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
          at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
          at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
Caused by: org.infinispan.CacheException: Unable to start cache loaders
          at org.infinispan.loaders.CacheLoaderManagerImpl.start(CacheLoaderManagerImpl.java:163)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:601)
          at org.infinispan.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.java:205)
          ... 130 more
Caused by: java.lang.IllegalArgumentException: Cannot load null class!
          at org.infinispan.util.Util.getInstance(Util.java:224)
          at org.infinispan.loaders.CacheLoaderManagerImpl.createCacheLoader(CacheLoaderManagerImpl.java:346)
          at org.infinispan.loaders.CacheLoaderManagerImpl.createCacheLoader(CacheLoaderManagerImpl.java:336)
          at org.infinispan.loaders.CacheLoaderManagerImpl.start(CacheLoaderManagerImpl.java:149)
          ... 135 more

更新

我逐步跟踪了 Infinispan 的源代码,并将错误范围缩小到类 org.infinispan.loaders.CacheLoaderManagerImpl 上的此方法。cfg 实例的类型为 org.infinispan.loaders.mongodb.MongoDBCacheStoreConfig,有趣的是,我在 Eclipse 的类路径中的任何库中都找不到它。所以我假设这个类是在运行时创建的?报告 NPE 错误是因为 cfg.getCacheLoaderClassName() 在第一行返回 null。

CacheLoader createCacheLoader(CacheLoaderConfig cfg, AdvancedCache<Object, Object> cache) throws Exception {
  CacheLoader tmpLoader = (CacheLoader) Util.getInstance(cfg.getCacheLoaderClassName(), cache.getClassLoader());

  if (tmpLoader != null) {
     if (cfg instanceof CacheStoreConfig) {
        CacheStore tmpStore = (CacheStore) tmpLoader;
        // async?
        CacheStoreConfig cfg2 = (CacheStoreConfig) cfg;
        if (cfg2.getAsyncStoreConfig().isEnabled()) {
           tmpStore = createAsyncStore(tmpStore, cfg2);
           tmpLoader = tmpStore;
        }

        // read only?
        if (cfg2.isIgnoreModifications()) {
           tmpStore = new ReadOnlyStore(tmpStore);
           tmpLoader = tmpStore;
        }

        // singleton?
        SingletonStoreConfig ssc = cfg2.getSingletonStoreConfig();
        if (ssc != null && ssc.isSingletonStoreEnabled()) {
           tmpStore = new SingletonStore(tmpStore, cache, ssc);
           tmpLoader = tmpStore;
        }
     }

     // load props
     tmpLoader.init(cfg, cache, m);
  }
  return tmpLoader;

}

4

0 回答 0