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

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

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



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5641897.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存