Trying to bind int value from properties file using spring
But everytime getting below exception :
Failed to instantiate [org.springframework.amqp.rabbit.connection.ConnectionFactory]:
Factory method 'connectionFactory' threw exception; nested exception is java.lang.NumberFormatException: For input string: \"${rabitmq.server.host.connectionclosetimeout}\"
Caused by: java.lang.NumberFormatException: For input string: \"${rabitmq.server.host.connectionclosetimeout}\""}}
My properties file look like below :
rabitmq.server.host.connectionclosetimeout=30000
My Bean
@Value("${rabitmq.server.host.connectionclosetimeout}")
private int connectionCloseTimeOut;
Configuration Class
@Configuration
@PropertySource("classpath:config/service.properties")
public class RabbitMqConfiguration {
@Value("${rabitmq.server.host.connectionclosetimeout}")
private Integer connectionCloseTimeOut;
/**
* Establishing connection
*
* @return
*/
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host);
connectionFactory.setCloseTimeout(connectionCloseTimeOut);
return connectionFactory;
}
}
If I add below bean then its working fine. But I want to work without below bean
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
I have also tried with below method :
@Value("#{new Integer.parseInt('${rabitmq.server.host.connectionclosetimeout}')}")
private int connectionCloseTimeOut;
It's also not working.
Please suggest what is way to get it working.