0

I want to have Spring Boot application to run as command line application.

I would like to provide additional properties that would come from command line arguments and be merged with properties in application.yaml

When I use Properties then application.yaml is omitted. How I can merge properties from two sources?

@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)

}
pixel
  • 24,905
  • 36
  • 149
  • 251

1 Answers1

1

You don't need pass the properties to the builder. SpringBoot will automatically merge properties from different sources for you. There is an order in which different sources will be handled.

Have a look here: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

abedurftig
  • 1,118
  • 1
  • 12
  • 24
  • Ok, but then I realized that when I use `SpringApplicationBuilder` then it's not loading properties from `application.yml` – pixel Jul 19 '19 at 09:39