Spring Boot Inherit application.properties from dependency

后端 未结 2 1000
面向向阳花
面向向阳花 2020-12-01 09:25

Let\'s say I have 5 Spring Boot Projects. All of them have a Maven dependency on a Spring Boot project No 6 with some shared/common classes. 5 independent projects have a lo

2条回答
  •  借酒劲吻你
    2020-12-01 10:00

    Currently spring boot doesn't provide inheriting properties.

    A spring boot application supports multiple property sources but the convention (read: built-in logic) for xxx.properties is to resolve the last xxx.properties if there are multiple properties files having the same file name.

    There are many solution to this.

    One possible solution is to

    1. apply a custom profile to the dependency
    2. include inheritable settings in the application-customprofile.properties
    3. have the dependent(s) set spring.profiles.include=customprofile in application[-{profile}].properties (note: if set in application.properties, it applies for all profiles)

    Another possible solution is to use a unique custom filename for the properties.

    • i.e. instead of using the default application.properties, use common.properties

提交回复
热议问题