简短的问题:
如何配置环境配置文件,甚至只是一个替代配置文件名
弹簧启动:运行?
长版本:
是的,我读过文档。http://docs.spring.io/spring-boot/docs/current/reference/html/index.html
我的应用程序配置设置位于 src/main/resources/application-mysql.properties 中:
# Specify the DBMS
spring.jpa.database = MYSQL
# Other Mysql config properties
spring.jpa.hibernate.ddl-auto=create
有一个相应的application-hsql.properties,其中包含与Hsql相同的一组配置选项。
没有 application.poperties
有对应的import.sql:
insert into users(name, email) values ('User One', '[email protected]')
insert into users(name, email) values ('Two User', '[email protected]')
单元测试的存在只是为了检查存储库中是否存在这些用户。
我相信每当使用 MySql 配置运行测试时,这些行都会添加到用户表中。当使用 hsql 运行测试时,mysql 数据库应该不受影响。
我在运行之间手动删除用户表,因为我想手动查看它何时存在。
1)如果我运行 mvn test,测试将使用配置的数据库:
mvn -Dspring.profiles.active=mysql clean test
生成 mysql 数据库行并
mvn -Dspring.profiles.active=hsql clean test
才不是。
2)如果我制作一个包,然后运行生成的 jar 文件,我可以指定一个配置文件名:
java -jar -Dspring.profiles.active=mysql ./target/app.jar
3)如果我使用 spring-boot:run 运行,则只会发现 application.properties 中的属性(此测试场景中不存在)。
mvn -Dspring.profiles.active=mysql clean spring-boot:run
spring-boot:run 在启动方面与运行单元测试和启动 jar 有何不同?数据库配置就是一个示例,但理论上我希望能够在应用程序在本地运行而不是生产配置时指定一组开发配置。