【问题标题】:how can I configure RedisHttpSessionConfigure to fallback if redis is not online如果 redis 不在线,如何将 RedisHttpSessionConfigure 配置为回退
【发布时间】:2015-10-18 08:50:23
【问题描述】:

我正在使用 spring-session + redis,如此处所述: http://docs.spring.io/spring-session/docs/current/reference/html5/guides/httpsession-xml.html

如何配置 RedisHttpSessionConfigure 以便本地开发不需要 redis 并且应用程序将简单地默认为容器会话处理?

【问题讨论】:

    标签: spring redis spring-session


    【解决方案1】:

    通常不建议这样做,因为您的开发环境与生产环境不同。将您的开发机器指向 Redis 实例应该很简单。

    如果需要支持,可以使用Spring profiles。例如,对于 XML,您可以使用以下内容:

    <beans profile="dev">
        <bean id="springSessionRepositoryFilter" class="org.springframework.web.filter.CharacterEncodingFilter"/>
    </beans>
    
    <beans profile="production">
        <context:annotation-config/>
        <bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"/>
        <bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"/>
    </beans>
    

    关键是要确保您的开发环境也有一个实现过滤器的 Bean,名为 springSessionRepositoryFilter。在这个例子中,我使用了CharacterEncodingFilter,它应该什么都不做,因为没有设置编码属性,但可以随意替换为你喜欢的任何东西。

    接下来您需要做的是activate your environments。例如,您可以使用

    -Dspring.profiles.active="production"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-05
      • 1970-01-01
      • 2019-02-28
      • 2013-03-15
      • 1970-01-01
      • 2019-06-04
      相关资源
      最近更新 更多