【发布时间】:2019-01-25 15:50:18
【问题描述】:
我正在制作一个在后端使用 Spring Boot、MySQL 和 Redis 并在前端使用 Angular 的应用程序。我想将它部署到 Heroku,这样我就可以使用我的前端,但我似乎无法为 Redis 配置远程 URL。为此,我在 Heroku 上安装了 Redis To Go 插件,并准备好了远程 URL。我只是不知道如何配置环境变量来访问它而不是 localhost 和默认端口 6379。
我在 application.properties 中添加了以下几行,但它仍然不起作用:
spring.redis.url= #URL
spring.redis.host= #HOSTNAME
spring.redis.password= #PASSWORD
spring.redis.port = #PORT
我不断收到以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis on localhost:6379; nested exception is com.lambdaworks.redis.RedisConnectionException: Unable to connect to localhost/127.0.0.1:6379
有什么方法可以配置它来访问远程 url 而不是 localhost?
我使用的是生菜而不是 Jedis,我的 HttpSessionConfig 文件是:
@EnableRedisHttpSession
public class HttpSessionConfig {
@Bean
public LettuceConnectionFactory connectionFactory() {
return new LettuceConnectionFactory();
}
}
【问题讨论】:
-
您实际上是使用“#HOSTNAME”作为 spring.redis.host 属性还是正确的主机名?如果没有,请将#HOSTNAME 替换为远程 url 中的主机名,然后重试。
-
我使用了正确的主机名
标签: java spring-boot redis lettuce