嵌入式redis无法启动

时间:2016-03-23 12:03:53

标签: java spring-security redis spring-boot

我正在使用embedded-redis 0.6版本和spring-session-data-redis 1.0.1.RELEASE我仍然得到以下例外:
我正在使用带有mvn spring-boot的spring boot:运行命令tomcat server启动但是嵌入式redis在运行时给出异常。

<dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-data-redis</artifactId>
             <version>1.0.1.RELEASE</version> 
        </dependency>
        <dependency>
            <groupId>com.github.kstyrc</groupId>
            <artifactId>embedded-redis</artifactId>
            <version>0.6</version>
        </dependency>



 Caused by: 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.dao.InvalidDataAccessApiUsageException: ERR Unsupported CONFIG parameter: notify-keyspace-events; nested exception is redis.clients.jedis.exceptions.JedisDataException: ERR Unsupported CONFIG parameter: notify-keyspace-events
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
            at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
            at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
            at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
            at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
            at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
            at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
            at com.springbootapp.config.Application.main(Application.java:16)
            ... 6 more
    Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: ERR Unsupported CONFIG parameter: notify-keyspace-events; nested exception is redis.clients.jedis.exceptions.JedisDataException: ERR Unsupported CONFIG parameter: notify-keyspace-events
            at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:44)
            at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:36)
            at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:37)
            at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:37)
            at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:210)
            at org.springframework.data.redis.connection.jedis.JedisConnection.setConfig(JedisConnection.java:633)
            at org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction.configure(ConfigureNotifyKeyspaceEventsAction.java:63)
            at org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration$EnableRedisKeyspaceNotificationsInitializer.afterPropertiesSet(RedisHttpSessionConfiguration.java:167)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
            ... 22 more
    Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR Unsupported CONFIG parameter: notify-keyspace-events
            at redis.clients.jedis.Protocol.processError(Protocol.java:117)
            at redis.clients.jedis.Protocol.process(Protocol.java:151)
            at redis.clients.jedis.Protocol.read(Protocol.java:205)
            at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
            at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:196)
            at redis.clients.jedis.Jedis.configSet(Jedis.java:2575)
            at org.springframework.data.redis.connection.jedis.JedisConnection.setConfig(JedisConnection.java:631)
            ... 26 more

1 个答案:

答案 0 :(得分:6)

错误通常发生在以下两种情况之一:

Redis版本太旧了

这似乎是最可能的答案。来自the documentation

  

要使示例正常工作,您必须在localhost上安装Redis 2.8+   使用默认端口(6379)运行它。或者,您可以更新   JedisConnectionFactory指向Redis服务器。

如果您不关心接收事件,可以通过creating a ConfigureRedisAction Bean禁用键空间通知设置:

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

或XML

<util:constant
    static-field="org.springframework.session.data.redis.config.ConfigureRedisAction.NO_OP"/>

或者,确保您运行的是Redis 2.8 +。

您的Redis实例已禁用或重命名了配置命令

嵌入式实例的情况不太可能,因为默认情况下配置。来自文档:

  

如果您正在使用@EnableRedisHttpSession的SessionMessageListener   并启用必要的Redis Keyspace活动   自动。但是,在安全的Redis环境中配置   命令已禁用。这意味着Spring Session无法配置   Redis Keyspace活动为您服务。禁用自动配置   将ConfigureRedisAction.NO_OP添加为bean。

     

例如,Java Configuration可以使用以下内容:

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

或XML

<util:constant
    static-field="org.springframework.session.data.redis.config.ConfigureRedisAction.NO_OP"/>