首页 > 代码库 > 【原】保存一下之前spring-session的redis单点登录配置文件【跨域】
【原】保存一下之前spring-session的redis单点登录配置文件【跨域】
由于先前在调试项目的时候需要做单点,但是项目是基于spring-session老版本做的单点登录,没有实现跨域登录,因为只是针对相同域名下的用户缓存进行存储而已,例如 http://127.0.0.1/wap 和 http://127.0.0.1/wap2 ,这样的话只要在 第一个域名登录后再去第二2个域名进行用户登录,则无需重复登录,但是如果是 http://127.0.0.1/wap 和 http://192.168.1/wap2 这样就没办法找到session。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:c="http://www.springframework.org/schema/c" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd ">
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="${redis.maxTotal}" />
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.host}" />
<property name="port" value="${redis.port}" />
<property name="password" value="${redis.auth}" />
<property name="poolConfig" ref="poolConfig" />
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<!-- 如果不配置Serializer,那么存储的时候智能使用String,如果用对象类型存储,那么会提示错误对象 can‘t cast to
String!!! -->
<property name="keySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="valueSerializer">
<bean
class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
</property>
</bean>
<bean id="redisTemplateC" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="keySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="valueSerializer">
<!-- 设置值的序列化器,不然保存到Redis时会出现十六进制问题 -->
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
</bean>
<!-- 将session放入redis -->
<bean id="redisHttpSessionConfiguration"
class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="httpSessionStrategy" ref="cookieHttpSessionStrategy"/>
</bean>
设置cookieName和path
<bean id="defaultCookieSerializer"
class="org.springframework.session.web.http.DefaultCookieSerializer">
<property name="cookieName" value="http://www.mamicode.com/DTL_SESSION_ID" />
<property name="cookiePath" value="http://www.mamicode.com/" />
</bean>
<bean id="cookieHttpSessionStrategy"
class="org.springframework.session.web.http.CookieHttpSessionStrategy">
<property name="cookieSerializer" ref="defaultCookieSerializer" />
</bean>
</beans>
【原】保存一下之前spring-session的redis单点登录配置文件【跨域】
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。