json - spring boot --spring.application.json 参数未设置

标签 json spring spring-boot

我有一个 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"}}}'

最佳答案

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

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

关于json - spring boot --spring.application.json 参数未设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40775388/

相关文章:

java - 删除 oneToOne 后 Spring Hibernate TransientPropertyValueException

java - Spring Boot 测试中的 MockBean 注解导致 NoUniqueBeanDefinitionException

javascript - 使用来自 Facebook 的 JavaScript 方法

javascript - 如何循环遍历具有许多 JSON 数组节点的 JSON 对象 jQuery

java - 如何将 ArrayList<object> 转换为 String,反之亦然

java - 解析 XML ServletContext 资源 BeanDefinitionStoreException

java - 使用 grails 配置 Hibernate

spring - 分段文件上传:Size exceed exception in spring boot return JSON error message

java - 为什么在 Spring Boot 中检索 mysql View 时出现 "unknown column"错误?

javascript - JSON 与 Angular JS 不起作用(Ionic 和 Cordova)