首页 > 解决方案 > Spring Boot 最新版本中 jdbctemplate 的 @autowired 问题

问题描述

下面是我的 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

标签: javaspringspring-bootoracle11gjdbctemplate

解决方案


您缺少 Oracle 数据库的 jdbc 驱动程序。

不幸的是,由于二进制许可,没有带有 Oracle Driver JAR 的公共存储库。尝试按照此答案将其添加到您的 pom中。


推荐阅读