java - Spring yaml 环境不与数据源一起工作

标签 java spring spring-data-jpa

我有一个 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: Error creating bean with name 'demoApplication': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.example.DbAccess com.example.DemoApplication.dbd; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbAccess': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.jdbc.core.JdbcTemplate com.example.DbAccess.jdbcTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.

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

最佳答案

正确答案是我打错了 :(

关于java - Spring yaml 环境不与数据源一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33388249/

相关文章:

spring - 将摘录投影添加到 Spring Data Rest 存储库会导致堆栈溢出错误

java - Android从JSON获取特定数据

java - Spring DefaultMessageListenerContainer、ActiveMQ 和消息重新传递

java - Android Studio登录系统数据库问题

spring - 通过 Spring Auditing 获取更改的字段

java - spring 范围 ="prototype"的目的是什么?

java - Spring 数据 JPA 存储库不保存到数据库

java - 当我从 cmd 重定向输出时,为什么输出文件为空?

java - 在查找方法中使用表达式

java - 在 Spring Data 上选择字段