【问题标题】:Getting initialization error connecting to Oracle Driver连接到 Oracle 驱动程序时出现初始化错误
【发布时间】:2022-01-07 20:30:29
【问题描述】:

在我的 Spring Boot 应用程序中,我更新了 application.properties 以连接到 Oracle DB:

spring.datasource.url = jdbc:oracle:thin:@//${mysql.service.host}:${mysql.service.port}/${mysql.service.database}
spring.datasource.username = ${mysql.service.username}
spring.datasource.password = ${mysql.service.password}
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

并在 build.gradle 文件中包含 Oracle Driver 依赖项:

运行时组:'com.oracle.database.jdbc',名称:'ojdbc11',版本:'21.1.0.0'

但仍然面临错误:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver
    org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650)
20 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver
at org.springframework.util.Assert.state(Assert.java:97)
    org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:223)
    org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:175)
    org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:43)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)

请对修复有任何建议吗?

【问题讨论】:

  • Oracle 数据库不是 MySQL。
  • 是的!对不起,我忘了提到 mysql.service.username 和 rest 只是其中有价值的变量
  • 驱动文件在你的类路径中吗?
  • 是的!仍然显示错误:(

标签: java spring oracle spring-boot


【解决方案1】:

有可能……

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

:)

【讨论】:

  • 谢谢!但是这个驱动有mysql驱动。我更多的是寻找Oracle驱动程序来连接到Oracle数据库spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
猜你喜欢
  • 2013-11-29
  • 1970-01-01
  • 2015-08-30
  • 1970-01-01
  • 2021-10-10
  • 1970-01-01
  • 2015-09-02
  • 2018-06-24
  • 1970-01-01
相关资源
最近更新 更多