【发布时间】:2017-04-08 02:34:47
【问题描述】:
我有一个 Spring Boot 应用程序,该应用程序当前具有设置以下属性的“mysql”配置文件:
spring.datasource.url =
spring.datasource.username =
spring.datasource.password =
在 /resources/application-mysql.properties 文件中。 这很好用。当我运行 mysql 配置文件时,它连接到本地 mysql 数据库。当我不运行 mysql 配置文件时,它使用默认的 h2 数据库。接下来我想摆脱 application.my-sql.properties 并通过命令行传递这些值。从文档here 中,我希望以下内容可以正常工作。但奇怪的是,它从来没有获得这些属性,而是运行 h2 数据库。
java -jar myapp-0.0.1-SNAPSHOT.jar --spring.application.json='{"spring": {"datasource": {"url":"jdbc:mysql://localhost:3306/db", "username":"user","password":"pw"}}}'
【问题讨论】:
-
您是否也尝试过作为系统参数? -Dspring.application.json=
-
我最终选择了活跃的个人资料。 java -Dspring.profiles.active=myprofile -jar myapp.jar
标签: json spring spring-boot