码迷,mamicode.com
首页 > 编程语言 > 详细

【原】保存一下之前spring-session的redis单点登录配置文件【跨域】

时间:2017-02-21 22:00:22      阅读:1043      评论:0      收藏:0      [点我收藏+]

标签:instance   log   目的   schema   jdk   can   nts   class   values   

       由于先前在调试项目的时候需要做单点,但是项目是基于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="DTL_SESSION_ID" />  
        <property name="cookiePath" value="/" />  
    </bean>  
           
     <bean id="cookieHttpSessionStrategy"  
        class="org.springframework.session.web.http.CookieHttpSessionStrategy">  
        <property name="cookieSerializer" ref="defaultCookieSerializer" />  
    </bean>  

</beans>

 

【原】保存一下之前spring-session的redis单点登录配置文件【跨域】

标签:instance   log   目的   schema   jdk   can   nts   class   values   

原文地址:http://www.cnblogs.com/zdd-java/p/6385162.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!