springboot 2.xに基づくredis配置と使用


背景を使う
  • 現在、会社が使用しているのはすべてスプリングブックt 1.5.x+oauth 2+redisです.oauth 2を学ぶ目的にかんがみて、簡単なデモを構築する.
  • demoプロジェクトはsprigbookを使用してt 2.6を基礎に構築された
  • です.
    問題
    警告が発生しました.redisに接続できませんでした.
    2018-10-18 12:00:50.136  WARN 1996 --- [io-10110-exec-2] o.s.s.o.provider.endpoint.TokenEndpoint  : Handling error: RedisConnectionFailureException, Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 172.19.103.47:6379
    2018-10-18 12:00:50.324  WARN 1996 --- [io-10110-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by handler execution: org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 172.19.103.47:6379
    
    処理前のpomファイル:
    
    			org.springframework.boot
    			spring-boot-starter-security
    		
    		
    			org.springframework.boot
    			spring-boot-starter-data-redis
    		
    		
    			org.springframework.security.oauth
    			spring-security-oauth2
    			${oauth2.version}
    		
    		
    			org.springframework.boot
    			spring-boot-starter-web
    		
    
    		
    			redis.clients
    			jedis
    		
    
    		
    			org.springframework.boot
    			spring-boot-devtools
    			runtime
    		
    またネット上で各種の処理方法を試しました.redis初期化方式を修正しても問題は解決されません.https://blog.csdn.net/weixin_39723544/article/details/80743074?utm_source=blogxgwz2)解決方法が見つかりました.ここでメモしておきます.
    pomファイルの設定を変更します.
    
    			org.springframework.boot
    			spring-boot-starter-data-redis
    			
    			
    				
    					redis.clients
    					jedis
    				
    				
    					io.lettuce
    					lettuce-core
    				
    			
    		
    
            
            
            
                org.apache.commons
                commons-pool2
                2.5.0
            
    
            
            
                com.alibaba
                fastjson
                1.2.47
            
    
    appication.yml設定:
    #boot2.x  
    spring:
      redis:
        database: 0 # Database index used by the connection factory.
        timeout: 0 # Connection timeout in milliseconds.
        jedis:
          pool:
            max-active: 8 # 
            max-idle: 8 # 
            max-wait: -1 # 
            min-idle: 1 # 
    
    # boot1.x  
    spring:
      datasource:
      redis:
        database: 0 # Database index used by the connection factory.
        timeout: 0 # Connection timeout in milliseconds.
        pool:
          max-active: 8 #
          max-idle: 8 # 
          max-wait: -1 # 
          min-idle: 1 #