Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set placeholder values in properties file in spring

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.

like image 534
Anjali Avatar asked Jan 01 '23 21:01

Anjali


1 Answers

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.

like image 137
Nitin Zadage Avatar answered Jan 03 '23 11:01

Nitin Zadage