【问题标题】:Spring yaml environment not working together with datasourceSpring yaml环境不与数据源一起工作
【发布时间】:2016-01-28 01:27:58
【问题描述】:

我有一个 application.yml 可以工作,并且在连接到数据库时正在使用:

spring:
 datasource:
  driverClassName: org.postgresql.Driver
  url: jdbc:postgresql://10.100.247.112:5432/ofbizBuchhandel
  username: buchhandel
  password: buchhandel

当我将环境配置文件添加到配置时:

spring:
 profiles: development
 datasource:
  driverClassName: org.postgresql.Driver
  url: jdbc:postgresql://10.100.247.112:5432/ofbizBuchhandel
  username: buchhandel
  password: buchhandel

我收到了这个错误

org.springframework.beans.factory.BeanCreationException: 错误 创建名为“demoApplication”的bean:注入自动装配 依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 自动装配字段:com.example.DbAccess com.example.DemoApplication.dbd; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 创建名为“dbAccess”的bean:注入自动装配 依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 自动装配字段:org.springframework.jdbc.core.JdbcTemplate com.example.DbAccess.jdbcTemplate;嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 用名字创建bean 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': 注入自动装配的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 自动装配字段:私有 javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 创建在类路径资源中定义的名称为“dataSource”的bean [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: 通过工厂方法实例化 Bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:失败 实例化 [javax.sql.DataSource]:工厂方法 'dataSource' 抛出 例外;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 确定数据库类型 NONE 的嵌入式数据库驱动程序类。如果 您想要一个嵌入式数据库,请在 类路径。

根据我在这里http://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-change-configuration-depending-on-the-environment 的理解,配置文件的设置看起来是正确的。

【问题讨论】:

  • 您是否在运行时指定了活动配置文件?因为你没有默认配置文件。
  • 我指定了个人资料,但有一个错字:(

标签: java spring spring-data-jpa


【解决方案1】:

正确答案是我打错了:(

【讨论】:

    猜你喜欢
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 1970-01-01
    • 2021-08-07
    • 2019-07-04
    • 1970-01-01
    • 2017-12-25
    相关资源
    最近更新 更多