我在Apache Karaf中运行了一个非常小的OSGI应用程序,它在OrientDB版本2.1.11上运行良好。但是当我尝试在新的2.2.3版本上启动它时,我遇到了以下错误:
Caused by: com.orientechnologies.orient.core.exception.ODatabaseException: Error on opening database 'remote:/localhost/testdb'
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.<init>(ODatabaseDocumentTx.java:187)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool$DatabaseDocumentTxPolled.<init>(OPartitionedDatabasePool.java:118)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool$DatabaseDocumentTxPolled.<init>(OPartitionedDatabasePool.java:114)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool.initQueue(OPartitionedDatabasePool.java:442)
当它尝试初始化数据库连接池时,在应用程序安装时发生此错误。经过一些调试后,我发现根问题出在com.orientechnologies.orient.core.Orient类的方法registerEngines()中,其中OrientDB类加载器试图找到OEngine接口的所有实现:
Iterator<OEngine> engines = OClassLoaderHelper.lookupProviderWithOrientClassLoader(OEngine.class, classLoader);
此调用仅返回2个实现,plocal和memory(与registerEngines() - orientdb-core位于同一个包中)。远程引擎(com.orientechnologies.orient.client.remote.OEngineRemote)位于orientdb-client软件包中,OrientDB类加载器无法找到它。
这是创建数据库连接轮询并产生描述错误的代码片段:
log.info("Creating OrientDB connection pool");
OGlobalConfiguration.NETWORK_BINARY_DNS_LOADBALANCING_ENABLED.setValue(true);
OPartitionedDatabasePool connectionPool = new OPartitionedDatabasePool(url, user, password);
log.info(String.format("Created OrientDB connection pool: url=%s", url));