spring-mvc.xml:
web.xml添加攔截器: 放前面
隻要使用标準的servlet api調用session,在底層就會通過Spring Session得到的,并且會存儲到Redis或其他你所選擇的資料源中。
這裡是我寫的一個demo:
index.jsp:
第一個tomcat
第二個tomcat
這裡利用上一篇nginx負載配置的兩個tomcat來測試。
首先通路 <code>http://192.168.99.100/feng/index/login.htm?username=nginx</code> 來觸發生成session。
檢視redis,發現session已經儲存到redis。
通路 <code>http://192.168.99.100/feng/index/index.htm</code> 來讀取session, 并重新整理多次。
發現在負載的情況下讀取session沒問題,并且是同一個session,成功實作負載+session共享!
以上是轉再:https://www.cnblogs.com/andyfengzp/p/6434287.html
下面是自己實作: 通過nginx負載均衡 分發到兩個tomcat上
tomcat1:

tomcat2
redis: