【发布时间】:2017-04-03 22:16:31
【问题描述】:
我有一个带有两个配置文件的 Spring Boot 应用程序:“dev”和“prod”。在“开发”配置文件中应该使用 H2 数据库,在“产品”中 - PostgreSQL。
它们在 pom.xml 中定义如下:
<profiles>
<profile>
<id>prod</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211.jre7</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>dev</id>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
pom.xml 中没有定义其他数据库。
在我的 application.properties 文件中,'prod' 配置文件被定义为活动:
spring.profiles.active = prod
此外,每个配置文件都有两个特定的属性文件:
应用程序-dev.properties:
spring.jpa.show-sql = true
和 application-prod.properties(我将我的应用部署到 AWS):
spring.datasource.url = jdbc:postgresql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
spring.datasource.username = ${RDS_USERNAME}
spring.datasource.password = ${RDS_PASSWORD}
spring.jpa.hibernate.ddl-auto = update
我使用以下 VM 选项启动我的 IntelliJ IDEA:
-Dspring.profiles.active="dev"
当我在本地启动程序时,我看到使用了“dev”配置文件(控制台中有消息“以下配置文件处于活动状态:dev”),但 H2 没有启动。我变成以下错误信息:
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath.
If you have database settings to be loaded from a particular profile you may need
to active it (the profiles "dev" are currently active).
请帮助我正确定义这些配置文件。
【问题讨论】:
标签: java spring maven spring-boot