2017-05-30 40 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