skip to Main Content

I just migrated from Spring boot 2 to Spring boot 3.

When I run the project I get the error

| Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:6379
| Caused by: java.net.ConnectException: Connection refused
|    at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
|    at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) ~[na:na]

I changed the redis dependency from

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-redis</artifactId>
    <version>2.3.3.RELEASE</version>
 </dependency>

to

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    <version>3.0.1</version>
</dependency>

My redis is running and I have tried to change the host from localhost to my local ip but still will not work.

Below are configs.

application.yml

spring:
  datasource:
    username: username
    password: password
    driver: org.postgresql.Driver
    test-on-borrow: true
    validation-query: SELECT 1
    tomcat:
      max-active: 1
  session:
    store-type: none
    timeout: 86400
  redis:
    host: 172.22.64.1
    port: 6379

docker-compose

  db:
    container_name: redis
    image: redis
    hostname: redis
    expose:
      - "6379"
    ports:
      - "6379:6379"

2

Answers


  1. I’m facing the same issue. Migrating from 2.7.7 to 3.0.1 resulted in that. My setup is a little bit different, though. So far, no clue…

    Error:

    Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost/<unresolved>:6379
    at app//io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
    at app//io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
    at app//io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:350)
    at app//io.lettuce.core.RedisClient.connect(RedisClient.java:216)
    at app//org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:111)
    at [email protected]/java.util.Optional.orElseGet(Optional.java:364)
    at app//org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:111)
    at app//org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1531)
    ... 143 more
    Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: localhost/127.0.0.1:6379
    

    Test class config:

    @Container
    static GenericContainer redis = new GenericContainer(DockerImageName.parse("redis:6.2-alpine")).withExposedPorts(6379);
    @DynamicPropertySource
    static void redisProperties(DynamicPropertyRegistry registry) {
        registry.add("spring.redis.url", () -> String.format("redis://%s:%d", redis.getHost(), redis.getFirstMappedPort()));
    } 
    
    Login or Signup to reply.
  2. I faced the same error after migrating from Spring Boot 2.7.4 to 3.0.1 and after a long time trying different things I could finally solve the issue by adapting the naming of some environment variables that were set in the configmap of my application deployment.

    I changed the following variable names:

      SPRING_REDIS_HOST: "your_host"
      SPRING_REDIS_PASSWORD: "your_password"
    

    to

    SPRING_DATA_REDIS_HOST: "your_host"
    SPRING_DATA_REDIS_PASSWORD: "your_password"
    

    I guess it is related to the changed property names since Spring Boot 3 (https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#appendix.application-properties.data).

    Hope it helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search