【发布时间】:2019-01-05 17:44:50
【问题描述】:
下面是我的 application.properties 文件
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@abc:1512:dbq
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
下面是我的 POM.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
我使用 eclipse 创建了新的 maven + Spring boot 和最新版本的项目。但是在尝试自动装配 JdbcTemplate 时出现以下错误。我已经在上面分享了我的属性文件和 pom.xml。
Error::
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'asurintApp': Unsatisfied dependency
expressed through field 'jdbcTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration$JdbcTemplateConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.Ill`enter code here`egalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver
【问题讨论】:
-
如果你使用spring-boot那么最好使用JPA。
-
当我添加依赖时"
org.springframework spring-jdbc 4.1.4.RELEASE dependency>" 而不是 "spring-boot-starter-jdbc" 然后考虑在你的配置中定义一个 'org.springframework.jdbc.core.JdbcTemplate' 类型的 bean。 -
Cannot load driver class: oracle.jdbc.driver.OracleDriver-> 你缺少ojdbc依赖 -
添加:
但得到同样的错误com.oracle ojdbc7 12.1.0 -
试试添加这个依赖项oracle ojdbc6 11.2.0.3
标签: java spring spring-boot oracle11g jdbctemplate