【问题标题】:spring boot --spring.application.json parameters not being setspring boot --spring.application.json 参数未设置
【发布时间】: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


【解决方案1】:

我可以确认这确实有效。正如 Vaelyr 在 cmets 中指出的那样,将其设置为系统参数是有效的:

-Dspring.application.json='{"spring":{"datasource":{"username":"yourusername","password":"yourpassword"}}}'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    • 2023-03-26
    • 2018-04-05
    • 2020-11-03
    • 2014-12-25
    • 1970-01-01
    相关资源
    最近更新 更多