我正在使用 Spring 构建一个 JavaEE 应用程序,我正在尝试将它与 DerbyEmbeddedDriver 连接起来。该应用程序将在 SAP Hana Cloud Platform 试用版上使用,因此我使用的是他们的 Tomcat 8 版本。
Tomcat 8 可以在以下位置找到:https://tools.hana.ondemand.com/
SAP HCP:https://account.hanatrial.ondemand.com/
启动Tomcat服务器时出现错误。这是我看到的:
Caused by: ERROR XJ041: Failed to create database 'memory:DemoDB', see the next exception for details. at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source) ... 113 more Caused by: ERROR XBM02: Startup failed due to missing functionality for org.apache.derby.iapi.types.DataValueFactory. Please ensure your classpath includes the correct Derby software. at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) at org.apache.derby.iapi.services.monitor.Monitor.missingImplementation(Unknown Source) at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source) at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source) at org.apache.derby.impl.services.monitor.FileMonitor.startModule(Unknown Source) at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source) at org.apache.derby.impl.db.BasicDatabase.boot(Unknown Source) at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source) at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source) at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(Unknown Source) at org.apache.derby.impl.services.monitor.BaseMonitor.createPersistentService(Unknown Source) at org.apache.derby.impl.services.monitor.FileMonitor.createPersistentService(Unknown Source) at org.apache.derby.iapi.services.monitor.Monitor.createPersistentService(Unknown Source) ... 110 more
Which regards to the error, I am using Maven and this is my Derby dependency config:
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.13.1.1</version>
</dependency>
所以我假设 Maven 应该将其添加到 Maven Dependencies 库中,因此我不需要在类路径中显式添加它,对吗?
关于数据源对象的创建。此 Tomcat 服务器在 Servers//config_master/connection_data/connection.properties 下有一个配置文件,其中包含:
#----------------------------------------
# Connection parameters for a local Derby database
# DB and tables are created automatically (if missing)
#----------------------------------------
javax.persistence.jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver
javax.persistence.jdbc.url=jdbc:derby:memory:DemoDB;create=true
javax.persistence.jdbc.user=demo
javax.persistence.jdbc.password=demo
eclipselink.target-database=Derby
#----------------------------------------
# Connection parameters MaxDB
#----------------------------------------
#javax.persistence.jdbc.driver=com.sap.dbtech.jdbc.DriverSapDB
#javax.persistence.jdbc.url=jdbc:sapdb://<host>/DEMO
#javax.persistence.jdbc.user=demo
#javax.persistence.jdbc.password=demo
#eclipselink.target-database=org.eclipse.persistence.platform.database.MaxDBPlatform
这由服务器使用,它会创建一个新的数据源并根据定义的名称将其注入(inject)到上下文中,所以当我想在应用程序中获取它时,我所做的就是:
@Configuration
public class DataSourceConfig {
@Bean
public DataSource dataSource() throws NamingException {
InitialContext ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/memory/DemoDB");
return dataSource;
}
}
您能指出我可能遗漏的任何内容吗?
最佳答案
我发现了问题...问题是 derby 依赖项作为测试依赖项在 pom.xml 中列出了两次...
这个 pom.xml 文件是从另一个项目中重用的,在清理它时跳过了它。
关于java - Derby 嵌入式驱动程序错误 XBM02 请确保您的类路径包含正确的 Derby 软件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40867163/