栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring:在Tomcat群集故障转移中,HttpSession为SPRING_SECURITY_CONTEXT返回空对象

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring:在Tomcat群集故障转移中,HttpSession为SPRING_SECURITY_CONTEXT返回空对象

Tomcat会话未复制,并且在节点之一发生故障时导致用户注销,配置

hazelcast
为实现会话复制,如下所示

步骤1:将以下依赖项添加到pom.xml

    <dependency>        <groupId>com.hazelcast</groupId>        <artifactId>hazelcast</artifactId>        <version>3.6.2</version>    </dependency>    <dependency>        <groupId>com.hazelcast</groupId>        <artifactId>hazelcast-wm</artifactId>        <version>3.6.2</version>    </dependency>

第2步:在现有过滤器的顶部添加以下代码段,

web.xml
以便首先将请求转到
hazelcast

<filter>    <filter-name>hazelcast-filter</filter-name>    <filter-class>com.hazelcast.web.spring.SpringAwareWebFilter</filter-class>    <!--        Name of the distributed map storing        your web session objects    -->    <init-param>        <param-name>map-name</param-name>        <param-value>my-sessions</param-value>    </init-param>    <init-param>        <param-name>config-location</param-name>        <param-value>/WEB-INF/hazelcast.xml</param-value>    </init-param>    <init-param>        <param-name>sticky-session</param-name>        <param-value>true</param-value>    </init-param>    <!-- Are you debugging? Default is false.-->    <init-param>        <param-name>debug</param-name>        <param-value>true</param-value>    </init-param></filter><filter-mapping>    <filter-name>hazelcast-filter</filter-name>    <url-pattern>/*</url-pattern>    <dispatcher>FORWARD</dispatcher>    <dispatcher>INCLUDE</dispatcher>    <dispatcher>REQUEST</dispatcher></filter-mapping><listener>    <listener-class>com.hazelcast.web.SessionListener</listener-class></listener>

步骤3:建立

hazelcast.xml
如下

<hazelcast    xsi:schemaLocation="http://www.hazelcast.com/schema/config http://www.hazelcast.com/schema/config/hazelcast-config-3.6.xsd"    xmlns="http://www.hazelcast.com/schema/config"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></hazelcast>

第4步:初始化

sessionRegistry
您的bean
applicationContext.xml

<bean id="sessionRegistry"      />

重新启动您的应用程序,并且会话复制可以在tomcat故障转移上运行

文档参考:
http : //hazelcast.org/use-
cases/clustering/
http://docs.hazelcast.org/docs/3.5/manual/html/websessionreplication.htmlhttp://docs.hazelcast.org/docs/ 3.6 / manual / html-single /
index.html#preface

配置参考:https :
//github.com/hazelcast/hazelcast-pre-samples/tree/master/hazelcast-
integration/spring-security



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/636034.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号