Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include _ in a numeric value in properties file?

How can I have _ (underscore) in my numerical property while injecting it with @Value annotation in Spring? If I include _ in my value, Spring throws TypeMismatchException.

.properties file:

min-score=20_000

java class:

@Value("${min-score}")
private int minScore;
like image 690
Mahozad Avatar asked Oct 29 '25 09:10

Mahozad


1 Answers

Use Spring EL in your @Value annotation to replace _ characters:

@Value("#{'${min-score}'.replace('_','')}")
private int minScore;
like image 125
Mahozad Avatar answered Nov 01 '25 00:11

Mahozad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!