我第一次使用Spring,并试图进行设置,以便我的代码可以访问Oracle数据库。我的application.properties中具有以下配置:
spring.datasource.url=jdbc:oracle:thin:@140.192.30.237:1521:def
spring.datasource.username=<username>
spring.datasource.password=<password>
spring.datasource.driver.class-name=oracle.jdbc.driver.OracleDriver
我的pom.xml包含以下依赖项:
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
但是我收到以下错误,并且不确定如何解决,我从搜索中发现了类似的错误,但没有一个解决了我的问题:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: oracle.jdbc.OracleDriver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class oracle.jdbc.OracleDriver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
感谢您解决此问题的提示。
答案 0 :(得分:5)
正如您的错误中提到的,问题出在您的配置上。 下一行,
spring.datasource.driver.class-name=oracle.jdbc.driver.OracleDriver
应更改为
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
请注意,它不是 driver.class-name ,而是 driver-class-name
答案 1 :(得分:0)
Add below dependency and repository in the pom
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<repositories>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
Also add the following properties in the application.properties
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe(SID)
spring.datasource.username=system
spring.datasource.password=pw
答案 2 :(得分:0)
在命令promt或您的ide中尝试项目目录pom.xml文件。
mvn全新安装
答案 3 :(得分:0)
我有同样的问题 将此依赖项添加到POM.xml文件中
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
答案 4 :(得分:0)
以下对 POM 的依赖应该可以工作。
<!-- https://mvnrepository.com/artifact/oracle/ojdbc6 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>