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

折月煮酒 提交于 2019-12-10 19:05:52

问题


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;

回答1:


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

@Value("#{'${min-score}'.replace('_','')}")
private int minScore;


来源:https://stackoverflow.com/questions/51090283/how-to-include-in-a-numeric-value-in-properties-file

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