How to include _ in a numeric value in properties

2019-07-09 01:17发布

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条回答
看我几分像从前
2楼-- · 2019-07-09 01:57

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

@Value("#{'${min-score}'.replace('_','')}")
private int minScore;
查看更多
登录 后发表回答