I have a Redis service running in localhost:6379 and the spring-boot microservice connects to this redis service by reading the hostname and port from the application.properties file.
@Configuration
public class RedisConfiguration {
/**
* redis host.
*/
@Value("${spring.redis.host}")
private String redisHost;
/**
* redis port.
*/
@Value("${spring.redis.port}")
private int redisPort;
@Bean
JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration redisConf = new RedisStandaloneConfiguration(redisHost, redisPort);
return new JedisConnectionFactory(redisConf);
}
In the application.properties file, the properties given are -
spring.redis.host=localhost
spring.redis.port=6379
This works Perfectly when i am running the microservice in default profile that is it uses the default application.properties from the /src/main/resources
folder.
Now the Challenge I am facing is that, when i run the microservice in test profile, it has to fetch the properties file from the config-server which clones it from a github repo.
In this scenario, the redis service is showing an error like this
[ERROR][2019-05-30 15:48:33,761][pool-1-thread-4|org.springframework.data.redis.listener.RedisMessageListenerContainer:handleSubscriptionException:651] Connection failure occurred. Restarting subscription task after 5000 ms
This error occurs only when i am getting the properties file from the config-service.
The application-test.properties in the github repo is also having the correct redis configurations.
Please help me resolve this issue.
Finally, after lot of debugging i found out what was going wrong. It was due to the unwanted space at the end of spring.redis.host=localhost
that was causing this issue.