How to set placeholder values in properties file in spring

Anjali :

Below is application.properties file

app.not.found=app with {0} name can not be found.

How to replace {0} with some value in spring?

I am using below code to read properties file values.

env.getProperty("app.not.found")

but not getting how to set placeholder values.

Nitin Zadage :

Use MessageFormat.format(String pattern, Object ... arguments). It accepts an array in second parameter, which will replace 0, 1 , 2 ... sequentially.

MessageFormat.format(env.getProperty("app.not.found"), obj)

obj will replace {0} in your string.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=128263&siteId=1
Recommended