Closed VidyasagarPandikashala closed 11 months ago
Thanks for the report but it's not clear why you believe that it's a Spring Boot issue. Have you, for example, verified that an application using a Redis client directly is able to connect when the Spring Boot app is not? Unfortunately, we don't have time to perform this problem determination for you. If you can demonstrate that it works without involving Spring Boot but does not work with Spring Boot then we can take another look.
The issue is that springboot application is not able to recogonize the redis running in the same container. I need clarification if any settings to be done on application.properties or in the controller class (eg. annotate some dependency related to redis) for the application to connect to the port of the redis application.
Tried running the same syntax and similar docker configuration in nodejs and it is working as expected. This raised my concern was if it is related to spring boot application and its configuration. If it is not the issue of the spring-boot I truly apologize for taking your precious time.
There's nothing obviously wrong in what you've shared thus far but it's hard to be certain as you haven't provided a complete picture.
Spring Boot knows nothing about Docker's networking. It is the Redis client and the JVM that are responsible for establishing the connection. If they're able to do so without Spring Boot then this may well be a Spring Boot problem but I think it's most likely to be a problem at the level of the JVM or the Redis Client. A Docker problem is also a possibility, although that's less likely if this works with NodeJS.
Thank you for the support. @wilkinsona
I see that you've now duplicated this on Stack Overflow. Closing.
I am facing a similar issue
@VidyasagarPandikashala did you solve this issue?
I found the issue.
In your application.properties
file.
Can you replace:
spring.redis.host=redis-server
spring.redis.port=6379
with
spring.data.redis.host=redis-server
spring.data.redis.port=6379
@wilkinsona Sorry I am raising an issue for the first time in github, I am sorry for the delay, I did not notice the notification in my github.
@bot-alert : Here is how I resolved the issue that I faced.
As @wilkinsona suggested that it might not be an issue with the springboot I just went through the codebase and found out I missed @Configuration
annotation.
When I was running the application normally, it did not throw any compilation error but when I ran the code in docker, it was giving log with some error.
@Configuration // this was missed
@EnableCaching
public class RedisConfig {
@Value("${spring.redis.host}")
private String host;
@Value("${spring.redis.port}")// discrepancy in the placeholder key name added here and the application.properties file
private Integer port;
@Bean
public JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName(host);
config.setPort(port);
return new JedisConnectionFactory(config);
}
@Bean
public RedisTemplate<String, Object> redisTemplate(){
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(jedisConnectionFactory());
redisTemplate.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
return redisTemplate;
}
}
version: '3'
services:
redis-server: # make sure this name matches your host name in application.properties
image: 'redis'
ports:
- "6379:6379"
springboot-app:
build: .
ports:
- "8080:8080"
Hope this helps.
I found the issue. In your application.properties file. Can you replace
spring.redis.host=redis-server
spring.redis.port=6379
byspring.data.redis.host=redis-server
spring.data.redis.port=6379
Thanks a lot,you saved my day
I found the issue. In your application.properties file. Can you replace
spring.redis.host=redis-server
spring.redis.port=6379
byspring.data.redis.host=redis-server
spring.data.redis.port=6379
many thanks
I found the issue.
In your
application.properties
file. Can you replace:spring.redis.host=redis-server spring.redis.port=6379
with
spring.data.redis.host=redis-server spring.data.redis.port=6379
thanks a lot
I am getting the same problem and have no resolution yet, both tried with "spring.data.redis.host" and also using the same container name in springboot conf and in docker-compose file. Any other idea?
The issue is only when springboot app try to connect Redis within container, otherwise access the redis connection from container while running the app in IDE is working fine. I tried to use the networking inside my docker-compose file but still not helped.
Here is my docker-compose:
version: '3'
services: spond-weather-app: build: ../ container_name: weather-app depends_on:
redis_app_net
redis-server: container_name: redis-server image: redis:6.2-alpine restart: always ports:
networks: redis_app_net: driver: bridge
Here is the springboot conf file:
server.port=8080 spring.redis.host=redis-server spring.redis.port=6379 spring.cache.type=redis
Any clue?
On Fri, Aug 16, 2024 at 10:43 PM Ashish Khatiwada @.***> wrote:
Please check if there are some config which might be the issue . Example:
@Bean public LettuceConnectionFactory redisConnectionFactory() { return new LettuceConnectionFactory(); }
this was the issue as is was overriding the host and port as far i remember. I removed this and voila its working now.
— Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-boot/issues/38774#issuecomment-2294216242, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5YZLNJ56V44IR2CDISU46LZRZP5LAVCNFSM6AAAAABAUKA62OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJUGIYTMMRUGI . You are receiving this because you commented.Message ID: @.***>
--
Regards, Noman Sadiq @. @.
Mobile # +47-45954552
@emi-emi671 Andy's comment above still holds true. Assuming you are using a supported version of Spring Boot, the properties should be spring.data.redis.host
and spring.data.redis.port
. Other than that, there is not enough information here for us to help you, and it is not clear that this is a Spring Boot problem and not a Docker Compose setup problem. Please post a question to StackOverflow with as much detail about your setup as possible.
About application
Simple backend applicaction that counts number of visits happened to be done by an user. Redis stores the data of the visits made.
ERROR DESCRIPTION
Springboot application is not able connect to the redis server even though it shows the redis and application are both in same docker network.
It throws error - White label Error (type=Internal Server Error, status=500).
Error in sprinboot-app container:
Dockerfile:
DockerCompose.yml
application.properties
VisitController.java
Commands run to check the issues
Command:
Output :
Command:
Output:
The Docker network inspection confirms that both visitsapplication-redis-server-1 and visitsapplication-springboot-app-1 containers are on the same Docker network named visitsapplication_default. Therefore, they should be able to communicate with each other using their service names (redis-server and springboot-app, respectively).