Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing int to spring property

Tags:

java

spring

I want to pass int instead of string which is default in spring PropertyPlaceholderConfigurer.

<property name="mailServerPort" value="${mail.port}" />

This give me error because mailServerPort is int type and ${mail.port} is string type.

How can I convert ${mail.port} to int?

like image 588
Mawia Avatar asked Feb 12 '13 13:02

Mawia


1 Answers

According to me the casting should work properly if the value of port is proper integer.

Still if you face the problem you can try SpringExpressionLanguage(SpEL) for conversion.

<property name="mailServerPort" value="#{ T(java.lang.Integer).parseInt(mail.port) }"/>

Hope this helps you.

like image 178
Japan Trivedi Avatar answered Sep 28 '22 09:09

Japan Trivedi