我有一个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:不能 autowire字段:com.example.DbAccess com.example.DemoApplication.dbd; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 创建名为'dbAccess'的bean:注入自动装配 依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 autowire字段: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:不能 autowire字段:private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration $ JdbcTemplateConfiguration.dataSource; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 在类路径资源中定义名为'dataSource'的bean [组织/ springframework的的/ boot /自动配置/ 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,配置文件的设置看起来是正确的。
答案 0 :(得分:1)
正确答案是我刚写错字:(