I'm creating a component for mail service configuration >>
@Component
@PropertySource("classpath:mail.properties")
public class Mail {
@Value("${email.config.host}")
private String host;
@Value("${email.config.port}")
private Integer port;
@Value("${email.config.username}")
private String username;
}
And my mail.properties file looks like >>
email.config.host=smtp.gmail.com
email.config.port=587
email.config.username=idontknowmyname@gmail.com
email.config.password=password
I tried to get my port value, but I got problem >
java.lang.NumberFormatException: For input string: "${email.config.port}"
Yes, I know this should be an Integer value but my @Value annotation converted** to String. So I tried this:
@Value("#{ T(java.lang.Integer).parseInt('${email.config.port}')}")
... got the same.
Host, username, password, etc. Loaded fine! How can I get my port value? Why PropertySource did not convert this parameter automatically?