1. 程式人生 > >springboot連線Azure Redis出現的問題

springboot連線Azure Redis出現的問題

spring:
  redis:
    host: xxxxxx.redis.cache.chinacloudapi.cn
    port: 6380
    password: xxxxxxxxxxxxxxxxxxxxxxxxxxx
    timeout: 5000ms
    ssl: true

配置檔案的配置,注意需不需要ssl=true。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer'
defined in org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR unknown command 'CONFIG'

然後我啟動時候報錯了,一臉懵逼呀。 後來找了一下原因,好像是不認識這個CONFIG命令 請參考這個地方的問答

解決方法,讓他不再執行config命令。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- 讓Spring Session不再執行config命令 --> <util:constant static-field="org.springframework.session.data.redis.config.ConfigureRedisAction.NO_OP"/>

springboot的也不要慌,看這:

    @Bean
    public static ConfigureRedisAction configureRedisAction() {
        return ConfigureRedisAction.NO_OP;
    }

搞定,收工。