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