spring-boot - 如何从命令行插入其他属性?
问题描述
我想让 Spring Boot 应用程序作为命令行应用程序运行。
我想提供来自命令行参数并与属性合并的其他属性application.yaml
当我使用Properties
then时application.yaml
被省略。如何合并来自两个来源的属性?
@SpringBootApplication
class MyMain
fun main(args: Array<String>) {
val properties = Properties().apply {
setProperty("foo", // value from command line args)
}
SpringApplicationBuilder(MyMain::class.java)
.web(WebApplicationType.NONE)
.properties(properties)
.initializers(BeansInitializer())
.run(*args)
}
解决方案
您不需要将属性传递给构建器。SpringBoot 会自动为你合并不同来源的属性。有一个顺序来处理不同的源。
看看这里:https ://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
推荐阅读
- python - WINDROSE 和同一图中的图形
- c++ - G ++编译器:无法写入文件
- python - Python pip 无法安装约束模块
- kendo-ui - 剑道网格调整大小列不显示其标题单元格的调整大小句柄
- scala - outworkers phantom disable table create for some but not all tables in a cassandra keyspace
- pivot - 雪花旋转
- mysql - mysql Nodejs pool.getConnection 返回未定义
- windows - Windows 驱动程序:在执行关键代码时防止上下文切换
- angular - Firebase Angular : How to retrieve and display data?
- webkit - Playwright webkit 无法运行 WebAssembly