java - @autowired 在 Spring Boot 最新版本中使用 jdbctemplate 的问题

标签 java spring spring-boot oracle11g jdbctemplate

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

相关文章:

java - 为什么spring警告消息是“org.springframework.web.servlet.PageNotFound”?

java - spring 框架(Java)中是否有相当于 phpinfo 的东西?

java - 在 Java Spring 的 REST 方法中返回后执行清理操作

spring - Spring Boot 中用于应用程序身份验证和管理身份验证的不同凭据?

java - 如何在J2ME应用程序中编写build.xml?

java - 在 PersonaC30 证卡打印机上进行 Jpanel 打印

java - 提取给定方法句柄的 @Nullable/@NonNull 注释

java - 在运行时获取列表对象的类型

java - 如何使用默认的 spring.datasource 启动 quartz 集群?

java - Spring Boot 使用 ssl 连接到 mongodb(对等证书验证失败)