我需要幫助。我不知道這個項目有什么問題。我無法連接到 h2 數據庫。即使我沒有保留任何對象,只是關閉連接,我也會收到錯誤消息。對不起,我知道,它被問了好幾次,但沒有一個答案適合我的情況。我得到的錯誤:2019 年 3 月 4 日晚上 11:00:24 org.hibernate.Version logVersion INFO:HHH000412:Hibernate Core {5.2.12.Final} 2019 年 3 月 4 日晚上 11:00:24 org.hibernate.cfg.Environment INFO:HHH000206:未找到 hibernate.properties 2019 年 3 月 4 日晚上 11:00:24 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity WARN:HHH90000012:已識別過時的休眠命名空間http://hibernate.sourceforge.net/hibernate-configuration . 使用命名空間http://www.hibernate.org/dtd/hibernate-configuration 反而??梢噪S時刪除對過時 DTD/XSD 命名空間的支持。2019 年 3 月 4 日晚上 11:00:24 org.hibernate.annotations.common.reflection.java.JavaReflectionManager 信息:HCANN000001:Hibernate Commons Annotations {5.0.1.Final} 2019 年 3 月 4 日晚上 11:00:25 org.hibernate .engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!) org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine .jdbc.env.spi.JdbcEnvironment] 在 org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:271) 在 org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233) 在 org.冬眠。##### Initial SessionFactory 創建失敗.org.hibernate.service.spi.ServiceException: 無法創建請求的服務 [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 線程“main”中的異常 java.lang.ExceptionInInitializerError:連接到數據庫錯誤!在 orm.hibernate.employees.HibernateUtils.(HibernateUtils.java:17) 在 orm.hibernate.employees.EmployeeRepository.addNewEmployee(EmployeeRepository.java:16) 在 orm.hibernate.employees.EmployeesApp.main(EmployeesApp.java:21)進程以退出代碼 1 結束
1 回答

POPMUISE
TA貢獻1765條經驗 獲得超5個贊
您的應用程序無法在運行時找到您的數據庫驅動程序,因此出現錯誤Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.h2.Driver。
更改您的 H2 依賴項,如下所示:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
<scope>runtime</scope> <!-- Here you are saying this dependency is needed at runtime, not just at testing -->
</dependency>
添加回答
舉報
0/150
提交
取消