spring-session共享登錄

spring-session web.xml配置

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/spring.xml,classpath:spring/dubbo-client.xml</param-value>
    </context-param>
    <!--
    這個(gè)要配置在所有的過濾器之前
    -->
     <filter>
        <filter-name>springSessionRepositoryFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        <async-supported>true</async-supported>
    </filter> 
    <filter-mapping>
        <filter-name>springSessionRepositoryFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>

spring.xml配置

<!--設(shè)置頭  -->
    <bean id="httpSessionStrategy" class="org.springframework.session.web.http.HeaderHttpSessionStrategy">
    <!--
    可設(shè)置自定義頭
    <property name="headerName" value="${access_token}"></property>
    -->
    </bean>

    <!-- springSession集成redis -->
    <bean
        class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
        <!-- 設(shè)置過期時(shí)間 -->
        <property name="maxInactiveIntervalInSeconds" value="1800" />
        <!--<property name="httpSessionStrategy" ref="httpSessionStrategy"/>-->
    </bean> 
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxTotal" value="${redis.pool.maxActive}" />
        <property name="maxIdle" value="${redis.pool.maxIdle}" />
        <property name="maxWaitMillis" value="${redis.pool.maxWait}" />
        <property name="testOnBorrow" value="true" />
    </bean>
    <bean id="redisConnectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="hostName" value="${redis.host}" />
        <property name="port" value="${redis.port}" />
        <property name="usePool" value="true" />
        <property name="database" value="${redis.db}"></property>
        <!-- <property name="poolConfig" ref="jedisPoolConfig" />
          <property name="sentinelConfig" ref="sentinelConfiguration"/> -->
          <!--哨兵不是必須-->
        <constructor-arg name="sentinelConfig" ref="sentinelConfiguration"/>
        <constructor-arg name="poolConfig" ref="jedisPoolConfig"></constructor-arg>
    </bean>

源碼:
https://github.com/ln0491/spring-session-demo

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,568評(píng)論 19 139
  • Spring Boot 參考指南 介紹 轉(zhuǎn)載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 47,273評(píng)論 6 342
  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,876評(píng)論 2 45
  • 今天年假已經(jīng)結(jié)束了,大部分的爸媽們都回到工作崗位上,在這個(gè)時(shí)候,你有想對(duì)孩子說的話嗎?如果沒有,就讓下面這個(gè)媽媽代...
    江蘇家學(xué)寶閱讀 1,127評(píng)論 0 0
  • 生活總是讓我們遍體鱗傷,但到后來,那些受傷的地方一定會(huì)變成我們最強(qiáng)壯的地方!
    帥也得忍著閱讀 199評(píng)論 0 1

友情鏈接更多精彩內(nèi)容