how to skip placeholder value if not supplied in properties file in spring boot?

前端 未结 3 1971
终归单人心
终归单人心 2020-12-22 03:52

I have a spring boot application that uses gradle. I have configured gradle to inject build parameters into application.properties.

Here is my gradle snippet.

<
3条回答
  •  渐次进展
    2020-12-22 04:24

    I solve this with Spring profiles. https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html

    In application.properties I have

    service.version=dev
    

    In application-production.properties I have

    service.version=${version}
    

    And finally this in the build.gradle file

    processResources {
        filesMatching('application-production.properties') {
            expand(project.properties)
        }
    }
    

    In dev, test and integration tests the version will be "dev", when running with the production profile it will use the build version.

    This also works when running the application directly from IntelliJ.

提交回复
热议问题