セッション共有を実現するためSpringSessionコア・コンフィギュレーション・ファイル(いないシングルサインオン異なるルートドメイン名の間(セッション共有)これは、より春のセキュリティフレームワークの実装を使用するように複雑になっています)

web.xmlにフィルタを追加します。1.:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>1_servlet8</display-name>

  <filter>
    <filter-name>springSessionRepositoryFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>springSessionRepositoryFilter</filter-name>
    <url-pattern>\/*</url-pattern>  <--\ 此处斜杠要去掉 -->
  </filter-mapping>
  
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>
 



2.Spring配置文件:

```cpp
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <import resource="classpath:applicationContext-springSession.xml"/>
</beans>

3.applicationContext-springSession.xmlプロフィール

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 启动Spring的注解  ,component-scan 包路径扫描用于扫描到我们自定的带有注解的,component-scan这个标签的作用包含annotation-config的功能 -->
    <context:annotation-config></context:annotation-config>

    <!-- 启动SpringSession, 并将Session存入Redis中 -->
    <bean id="redisHttpSessionConfiguration" class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
        <!-- 设置Cookie的存放规则-->
        <property name="cookieSerializer"  ref="defaultCookieSerializer"/>

    </bean>

    <bean id="defaultCookieSerializer" class="org.springframework.session.web.http.DefaultCookieSerializer">
        <!-- 设置Cookie的访问路径 用于实现同一个域名下不同的项目中的Session共享-->
        <property name="cookiePath" value="/"/>
        <!-- 设置Cookie的域名 ,用于实现同根域名下 不同的二级子域名的Session共享问题
            注意:在Tomcat8(包括)以后域名设置不需要添加 . 例如myweb.com
                  在Tomcat8(不包括)以前域名设置需要添加 . 例如 .myweb.com
         -->
        <property name="domainName" value="myweb.com"/>

    </bean>
    <!-- 配置jedis连接工厂,用于连接redis -->
    <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="hostName" value="192.168.31.128"/>
        <property name="port" value="6379"/>
        <property name="password" value="123456"/>
    </bean>

</beans>

インタビューの概要:どのように我々は共有にセッションを達成していますか?
1>まず:私たちは、セッションはRedisのに格納され、SpringSession技術を使用し、そして
2>私たちは、ストレージ・ルールについて設定:設定し
、その属性オブジェクトの型であるプロパティcookieSerializer RedisHttpSessionConfigurationクラス、REFのように、基準値:defaultCookieSerializer
3。このクラスでDefaultCookieSerializerは
パスに基づいて1>セット値:名=「cookiePath」そのプロパティセット
2>ドメインのプロパティ設定:名=「ドメイン名を」。

公開された388元の記事 ウォン称賛40 ビュー10万+

おすすめ

転載: blog.csdn.net/qq_30347133/article/details/105025299