Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:6379

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"
like image 705
Darotudeen Avatar asked Sep 20 '25 12:09

Darotudeen


1 Answers

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

like image 162
pamin Avatar answered Sep 23 '25 02:09

pamin