下面是我的 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 和最新版本的项目。但尝试 Autowiring 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
最佳答案
您缺少 Oracle 数据库的 jdbc 驱动程序。
不幸的是,由于二进制许可证,没有包含 Oracle 驱动程序 JAR 的公共(public)存储库。尝试将其添加到您的 pom 中 this answer .
关于java - @autowired 在 Spring Boot 最新版本中使用 jdbctemplate 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51577624/