Spring Gateway 无法连接 Redis。

huangapple go评论65阅读模式
英文:

spring gateway can't connect redis

问题

Spring网关无法读取或连接到Redis...
出现如下错误:

org.springframework.data.redis.RedisConnectionFailureException: 无法连接到Redis
...
导致原因:io.lettuce.core.RedisConnectionException:无法连接到localhost/<未解析>:6379

问题是Redis配置在特定IP上,而不是本地,位于application.yml文件中:

spring:
  redis:
    host: 1.2.3.4
    port: 6379
    password: passw
    database: 0
    timeout: 3000
    lettuce:
      pool:
        max-active: 8
        max-idle: 8
        min-idle: 2
        max-wait: 5000ms

我无法通过telnet连接到Redis,但明显它甚至没有尝试连接到远程主机,而是连接到本地...

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.0.5'
	id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.example'
sourceCompatibility = '17'
repositories {
	mavenCentral()
}
ext {
	set('springCloudVersion', "2022.0.1")
}
dependencies {
	implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
	// --- cache
	implementation 'org.springframework.boot:spring-boot-starter-cache'
	implementation 'com.github.ben-manes.caffeine:caffeine:3.1.5'
	// --- redis
	implementation group: 'org.springframework.data', name: 'spring-data-redis', version: '3.0.4'
	implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive'
    //
	implementation 'org.springframework.cloud:spring-cloud-starter-loadbalancer'
	implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j'
}

dependencyManagement {
	imports {
		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
	}
}
tasks.named('test') {
	useJUnitPlatform()
}

可能的原因是什么?

英文:

Spring gateway cant' read or connect to redis...
Getting such error:

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis
...
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost/&lt;unresolved&gt;:6379

The problem is redis configured not locally but on specific ip, application.yml:

spring:
  redis:
    host: 1.2.3.4
    port: 6379
    password: passw
    database: 0
    timeout: 3000
    lettuce:
      pool:
        max-active: 8
        max-idle: 8
        min-idle: 2
        max-wait: 5000ms

I can't connect to redis via telnet, but obviously it's not even trying to connect to remote host, but instead connecting locally...

plugins {
	id &#39;java&#39;
	id &#39;org.springframework.boot&#39; version &#39;3.0.5&#39;
	id &#39;io.spring.dependency-management&#39; version &#39;1.1.0&#39;
}
group = &#39;com.example&#39;
sourceCompatibility = &#39;17&#39;
repositories {
	mavenCentral()
}
ext {
	set(&#39;springCloudVersion&#39;, &quot;2022.0.1&quot;)
}
dependencies {
	implementation &#39;org.springframework.cloud:spring-cloud-starter-gateway&#39;
	// --- cache
	implementation &#39;org.springframework.boot:spring-boot-starter-cache&#39;
	implementation &#39;com.github.ben-manes.caffeine:caffeine:3.1.5&#39;
	// --- redis
	implementation group: &#39;org.springframework.data&#39;, name: &#39;spring-data-redis&#39;, version: &#39;3.0.4&#39;
	implementation &#39;org.springframework.boot:spring-boot-starter-data-redis-reactive&#39;
    //
	implementation &#39;org.springframework.cloud:spring-cloud-starter-loadbalancer&#39;
	implementation &#39;org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j&#39;
}

dependencyManagement {
	imports {
		mavenBom &quot;org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}&quot;
	}
}
tasks.named(&#39;test&#39;) {
	useJUnitPlatform()
}

Why could be the cause?

答案1

得分: 0

感谢 @tobifasc,修复方法是更改Redis配置为 spring.data.redis...

英文:

Thanks to @tobifasc, the fix is to change redis configuration to spring.data.redis...

huangapple
  • 本文由 发表于 2023年4月1日 01:10:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75901082.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定