[英]Pass gradle command line arguments to application.properties
I have a Spring Boot Gradle application and many MySQL servers and databases.我有一个 Spring 启动 Gradle 应用程序和许多 MySQL 服务器和数据库。 In different scenarios, I want to start the application with different databases or create them if they do not exist.
在不同的场景中,我想用不同的数据库启动应用程序,或者如果它们不存在则创建它们。 I want to use this mechanism with command line arguments.
我想将此机制与命令行 arguments 一起使用。 The URL for database is stored in application.properties file of Spring:
数据库的URL存储在Spring的application.properties文件中:
spring.datasource.url=jdbc:mysql://localhost:3306/mydb1?createDatabaseIfNotExist=true&useSSL=true
I want to run gradle with command line arguments that will apply to the application.properties file so in my head will be something like this.我想用命令行 arguments 运行 gradle,这将适用于 application.properties 文件,所以在我的脑海中会是这样的。
application.properties: spring.datasource.url=jdbc:mysql://${linkNewDB}?createDatabaseIfNotExist=true&useSSL=true
application.properties:
spring.datasource.url=jdbc:mysql://${linkNewDB}?createDatabaseIfNotExist=true&useSSL=true
And to run the program as: gradle bootRun -Pargs=--linkNewDB="someNewDB:3309"
并将程序运行为:
gradle bootRun -Pargs=--linkNewDB="someNewDB:3309"
Does anybody know how can I achieve this mechanism?有谁知道我怎样才能实现这种机制? I tried different options but none of them worked.
我尝试了不同的选择,但都没有奏效。 Thanks!
谢谢!
How about changing the whole URL, like this:改变整个URL怎么样,像这样:
gradle bootRun --args='--spring.datasource.url=jdbc:mysql://someNewDB:3309?createDatabaseIfNotExist=true&useSSL=true'
reference: https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#running-your-application.passing-arguments参考: https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#running-your-application.passing-arguments
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.