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

人盡茶涼 提交于 2019-11-29 17:01:39

I've resolved this by adding into application.yml the following:

${version?:unknown}

It also work from cli:gradle bootRun and also from IntelliJ and you don't have to call the Gradle task processResources before launching in IntelliJ or use spring profiles.

This work with Gradle ver:4.6 and also Spring Boot ver: 2.0.1.RELEASE.
Hope it helps ;)

I have the same problem - really annoying. Best solution I have found so far is to save a run/debug configuration in IntelliJ and then go in an edit the configuration, specifying that the gradle task processResources should be executed before launch.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!