How can I override Spring Boot application.properties programmatically?

后端 未结 10 1712
失恋的感觉
失恋的感觉 2020-11-29 18:33

I have jdbc property files which I take from external configuration web-service In spring boot in order to set mysql props it\'s easy as adding those to application.properti

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 19:12

    If you need do to this for testing purposes: since spring-test 5.2.5 you can use @DynamicPropertySource:

        @DynamicPropertySource
        static void setDynamicProperties(DynamicPropertyRegistry registry) {
            registry.add("some.property", () -> some.way().of(supplying).a(value) );
        }
    

    Takes precedence over pretty much all of the other ways of supplying properties. The method must be static though.

提交回复
热议问题