redis 原因:io. netty. channel.抽象通道$带注解的连接异常:连接被拒绝:本地主机/127.0.0.1:6379

1tuwyuhd  于 2023-01-20  发布在  Redis
关注(0)|答案(1)|浏览(344)

我刚刚从Sping Boot 2迁移到Spring Boot 3。
当我运行项目时,我收到错误

| 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]

我将redis依赖项从

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

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

我的redis正在运行,我已经尝试将主机从localhost更改为我的本地ip,但仍然不起作用。
以下是配置。

应用程序.yml
spring:
  datasource:
    username: dt_viewer
    password: dt_viewer
    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
停靠器-合成
db:
    container_name: redis
    image: redis
    hostname: redis
    expose:
      - "6379"
    ports:
      - "6379:6379"
wgx48brx

wgx48brx1#

我也面临同样的问题。从2.7.7迁移到3.0.1导致了这个问题。不过我的设置有点不同。到目前为止,还没有线索...
错误:

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 java.base@17.0.3/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

测试类配置:

@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()));
}

相关问题