2017-05-30 344 views
2

我在AWS上托管我的应用程序。我已经配置我的财产文件,请按照以下错误redis客户端jedis HostAndPort不能解析localhost地址

spring.redis.host = {AWS主机端点} spring.redis.port = 6379

我的应用程序的工作之间的连接。但是,在连接到aws主机端点之前,spring会尝试始终连接到本地主机,因此会抛出错误。错误如下所示。

2017-05-30 10:37:58.203 [main] ERROR redis.clients.jedis.HostAndPort: 
cant resolve localhost address 

我如何解决此,请谢谢

编辑 下面显示了我的Redis的配置类

@Configuration 
@EnableCaching 
public class RedisCacheConfig { 

    final Logger logger = LoggerFactory.getLogger(RedisCacheConfig.class); 

    JedisConnectionFactory connectionFactory; 

    @Autowired 
    public RedisCacheConfig(JedisConnectionFactory connectionFactory) { 
     this.connectionFactory = connectionFactory; 
    } 

    @Bean 
    @Autowired 
    public CacheManager getCacheManager(CacheExpiration expiration) { 
     RedisCacheManager manager = new RedisCacheManager(getRedisTemplate()); 
     manager.setExpires(expiration.getMapper()); 
     //expiration.getMapper(); 
     return manager; 
    } 

    @Bean 
    public RedisTemplate getRedisTemplate() { 
     RedisTemplate template = new RedisTemplate(); 
     template.setConnectionFactory(connectionFactory); 
     template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); 
     return template; 
    } 
} 
+3

让我给你google吧....这是一个杰迪斯的bug:https://github.com/xetorthio/jedis/issues/1424 – mp911de

回答

2

这个错误似乎Jedis一直fixed 6月15日因此应纳入在下一个版本中。

与此同时,您可以随时构建最新的主人并在您的项目中使用该JAR。请记住在项目中包含Jedis的依赖关系。

为了建立从最新Jedis主(这是在版本3.0.0-SNAPSHOT此刻)一个JAR:

$ git clone https://github.com/xetorthio/jedis.git 
$ cd jedis 
$ mvn -Dmaven.test.skip=true package 
$ mkdir -p /path/to/your/project/lib 
$ cp target/jedis-3.0.0-SNAPSHOT.jar /path/to/your/project/lib/ 

的build.gradle片段与包括依赖关系:

dependencies { 
    file project.file("lib/jedis-3.0.0-SNAPSHOT.jar") 
    compile "org.slf4j:slf4j-api:1.7.22" 
    compile "org.apache.commons:commons-pool2:2.4.2" 
} 

如果您想使用最新版本,只需在顶部添加补丁,您可以像下面这样将其选择到2.9.0标签:

$ git clone https://github.com/xetorthio/jedis.git 
$ cd jedis 
$ git checkout jedis-2.9.0 
$ git cherry-pick 42a6523041e710087640ceaab11d3abcd34f3a72 

这将导致冲突,您必须合并,但是kdiff3会自动解决所有冲突,因此取决于您使用的合并工具,除了运行$ git mergetool以外,可能不需要执行任何其他操作并按[enter ]。

在解决了上面刚刚构建的冲突之后,您将最终得到一个名为的JAR替代jedis-2.9.0-SNAPSHOT.jar