我使用Neo4j 1.9.4进行项目,我遇到了一个奇怪的行为:
我有一段效果很好的代码。我已经用常春藤文件设置了类路径,一切正常。
public static void main(String[] args) {
// the cache providers
ArrayList<CacheProvider> cacheList = new ArrayList<CacheProvider>();
System.out.println("Creating db configuration");
cacheList.add(new SoftCacheProvider());
// the kernel extensions
LuceneKernelExtensionFactory lucene = new LuceneKernelExtensionFactory();
List<KernelExtensionFactory<?>> extensions = new
ArrayList<KernelExtensionFactory<?>>();
extensions.add(lucene);
// the database setup
GraphDatabaseFactory gdbf = new GraphDatabaseFactory();
gdbf.setKernelExtensions(extensions);
gdbf.setCacheProviders(cacheList);
GraphDatabaseService db = gdbf.newEmbeddedDatabase("/tmp/test");
}
问题是当我尝试将cacheList.add(new SoftCacheProvider())
更改为cacheList.add(new WeakCacheProvider())
时出现以下错误:
java.lang.IllegalArgumentException: No provider for cache type 'soft'. Cache providers are loaded using java service loading where they register themselves in resource (plain-text) files found on the class path under META-INF/services/org.neo4j.kernel.impl.cache.CacheProvider. This missing provider may have been caused by either such a missing registration, or by the lack of the provider class itself.
at org.neo4j.kernel.InternalAbstractGraphDatabase.create(InternalAbstractGraphDatabase.java:356)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:252)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:106)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:88)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:207)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:69)
at ttt.App.main(App.java:34)
如果我尝试使用NoChacheProvider或StrongCacheProvider,也会出现同样的错误。
我尝试使用以下内容添加文件META-INF/services/org.neo4j.kernel.impl.cache.CacheProvider
,但它不会改变任何内容。
org.neo4j.kernel.impl.cache.WeakCacheProvider
org.neo4j.kernel.impl.cache.SoftCacheProvider
org.neo4j.kernel.impl.cache.NoCacheProvider
org.neo4j.kernel.impl.cache.StrongCacheProvider
你知道发生了什么吗?我不明白为什么只有一种缓存提供程序类型正在运行。
请注意,我必须使用Neo4j 1.9.4并且我无法更改它。
编辑:我的项目是一个基本的eclipse插件项目,没有任何其他依赖
Edit2:另一个有趣的一点是,如果我尝试使用Map<String,String>
配置数据库,即使是<"cache_type","soft">
,我也会遇到同样的错误。
public static void main(String[] args) {
Map<String,String> config = new HashMap<String,String>();
config.put("cache_type", "soft");
GraphDatabaseService db = null;
db = new EmbeddedGraphDatabase("/tmp/test", config, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
}
java.lang.IllegalArgumentException: No provider for cache type 'soft'. Cache providers are loaded using java service loading where they register themselves in resource (plain-text) files found on the class path under META-INF/services/org.neo4j.kernel.impl.cache.CacheProvider. This missing provider may have been caused by either such a missing registration, or by the lack of the provider class itself.
at org.neo4j.kernel.InternalAbstractGraphDatabase.create(InternalAbstractGraphDatabase.java:356)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:252)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:106)
at ttt.App.main(App.java:36)
答案 0 :(得分:2)
尝试直接在配置中指定它,如下所示:
GraphDatabaseService db = gdbf.newEmbeddedDatabaseBuilder('path/to/db').setConfig(GraphDatabaseSettings.cache_type, WeakCacheProvider.NAME).newGraphDatabase()
当然,我没有在1.9.4中试过这个,但是,也许值得一试。