How to override application.properties during production in Spring-Boot?

后端 未结 8 898
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 13:00

I\'m using spring boot and application.properties to select a database during development by @Configuration @Profile(\"dev\").

spri         


        
8条回答
  •  悲哀的现实
    2020-12-04 13:35

    UPDATE: this is a bug in spring see here

    the application properties outside of your jar must be in one of the following places, then everything should work.

    21.2 Application property files
    SpringApplication will load properties from application.properties files in the following    locations and add them to the Spring Environment:
    
    A /config subdir of the current directory.
    The current directory
    A classpath /config package
    The classpath root
    

    so e.g. this should work, when you dont want to specify cmd line args and you dont use spring.config.location in your base app.props:

    d:\yourExecutable.jar
    d:\application.properties
    
    or
    
    d:\yourExecutable.jar
    d:\config\application.properties
    

    see spring external config doc

    Update: you may use \@Configuration together with \@PropertySource. according to the doc here you can specify resources anywhere. you should just be careful, when which config is loaded to make sure your production one wins.

提交回复
热议问题