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
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:
Test class config:
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:
to
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