【问题标题】:Error creating bean with name 'jpaVendorAdapter' defined in class path resource在类路径资源中定义名称为“jpaVendorAdapter”的 bean 创建错误
【发布时间】:2019-12-30 15:44:52
【问题描述】:

尝试在 Cloud Foundry 中部署 springboot 项目。出现以下错误。

原因: org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名称为“entityManagerFactoryBuilder”的bean时出错 类路径资源 [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: 通过方法表达的不满足的依赖关系 'entityManagerFactoryBuilder' 参数 0;嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 创建在类路径中定义的名称为“jpaVendorAdapter”的 bean 资源 [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: 通过工厂方法实例化 Bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.orm.jpa.JpaVendorAdapter]:工厂 方法“jpaVendorAdapter”抛出异常;嵌套异常是 java.lang.RuntimeException:驱动程序 com.microsoft.sqlserver.jdbc.SQLServerDriver 声称不接受 jdbcUrl, ${vcap.services.xxx.credentials.jdbcUrl}

application.properties

spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect

spring.datasource.url=${vcap.services.xxx.credentials.jdbcUrl}
spring.datasource.username=${vcap.services.xxx.credentials.username}
spring.datasource.password=${vcap.services.xxx.credentials.password}

build.gradle

implementation 'org.springframework.boot:spring-boot-starter-web'

//cloud connector
implementation 'org.springframework.boot:spring-boot-starter-cloud-connectors'

//database
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'


implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc'

implementation group: 'com.microsoft.sqlserver', name: 'mssql-jdbc'

compile group: 'org.springframework.cloud', name: 'spring-cloud-cloudfoundry-connector'

预期:应该部署并运行 实际:标题错误

【问题讨论】:

    标签: sql-server spring-boot spring-data-jpa cloud-foundry mssql-jdbc


    【解决方案1】:

    您应该从项目中删除 'org.springframework.boot:spring-boot-starter-cloud-connectors'group: 'org.springframework.cloud', name: 'spring-cloud-cloudfoundry-connector' 依赖项。

    当 Spring Cloud Connectors jar 位于类路径上时,它们将为在 VCAP_SERVICES 中检测到的服务创建连接 bean(例如,在您的情况下为 Datasource bean)。因为连接器正在创建连接 bean 而不是 Spring Boot,所以您的 spring.datasource 属性将被忽略。从项目中删除连接器将允许 Boot 使用您的属性创建连接。

    或者,您可以选择使用Java CFEnv 自动从VCAP_SERVICES 设置spring.datasource 属性(一旦从项目中删除连接器)。

    【讨论】:

      猜你喜欢
      • 2015-10-16
      • 2019-01-22
      • 2019-08-17
      • 2021-09-20
      • 2022-01-18
      • 2019-06-16
      • 2021-02-26
      相关资源
      最近更新 更多