Spring Boot Session 会话管理

Spring boot入门系列(三):使用Redis进行Session的管理 前言:本文所用jdk版本为:jdk1.8.0_111版本;Spring boot1.5.8版本,工程仍沿用上一篇文章的工程。 一、准备好Redis服务         提到Redis相信很多人都知道它是做什么的,这里不过多做阐述,本文主要看Spring boot如何集成Redis来存储Session,所以首先要准备好一个可用的redis服务。 二、 添加pom依赖 阅读详情

Spring Boot Session

会话管理是用于安全控制一个用户或者实体对基于网络的应用/服务的多个请求的过程。

HTTP用于网站和浏览器之间的交流,而会话则是同一个用户创建的一系列的HTTP请求和事务。

会话管理的实现规定了用户、网络应用之间共享和持续交换会话ID的过程。

由于HTTP协议的无状态,为了跟踪客户的行为,我们需要会话管理。会话管理是一个网络容器框架,用于为特定的用户储存会话数据。

我们可以通过以下方法处理会话:

  1. Cookies

    网站发送的数据被储存在用户的本地浏览器中

  2. 隐藏的表达字段

    在隐藏的数据中,对用户不可见也不可修改,当用户提交表单时,隐藏数据会被发送。

  3. URL重写

    修改URL的参数

  4. HttpSession(网络会话)

    允许数据与单个访问者绑定

在分布式环境中,我们可以通过以下方式管理会话:

  • 粘性会话(Sticky Session)

    在这种类型的会话中,负载均衡将把通过一个客户的请求路由到同一个节点,如果这个节点发生故障,则会话会丢失。

  • 复制会话(Session Replication)

    为了克服粘性会话的问题,会话复制将会话数据复制到多个服务器,当任何节点发生故障后,会话数据可以转移到另外的节点。

  • 持久数据储存中的会话数据(Session Data in a Persistent DataStore)

    还有一种情况下,会话数据并不会储存在服务器中,取而代之的是,它会被储存在数据库里,并且拥有唯一id SESSION_ID。

Spring Session

Spring Session包含下述组件:

  • Spring Session Core

    Spring Session的核心APIs

  • Spring Session Data Redis

    提供Redis数据库会话管理的会话存储库

  • Spring Session JDBC

    提供关系数据库会话管理的会话存储库

  • Spring Session Hazelcast

    提供Hazelcast会话管理的会话存储库

默认情况下,Apache Tomcat在内存中储存HTTP会话管理的对象。为了管理Spring Boot 会话管理,HTTPSession会被用于通过Spring Session JDBC在持久层中存储会话信息。

maven中导入

<dependency>
			<groupId>org.springframework.session</groupId>
			<artifactId>spring-session-core</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.session</groupId>
			<artifactId>spring-session-jdbc</artifactId>
		</dependency>

创建Controller

为了处理用户的请求,处理用户的数据并将数据存储在会话的 NOTES_SESSION 属性中。

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax
如何在Spring Boot中实现分布式会话管理? 除了使用默认配置外,Spring Session 还允许你通过实现特定接口来自定义会话存储逻辑。例如,如果你想改变如何序列化会话数据,可以创建自己的Serializer实现。 阅读详情

相关推荐

Spring boot 整合 redisson ,spring-session

Spring boot 整合 redisson ,spring-session整合Redisson整合Spring Session会话管理器参考文章 整合Redisson 在项目中引入封装好的redisson-spring-boot-starter依赖(也可以根据封装代码或者官网自己实现,从简单角度建议根据封装代码实现自己需要的) &amp;lt;dependency&amp;gt; &amp;lt;g...

不会写博客 5897

*Spring Session 的一个重要里程碑版本(Milestone 4)**,专为与 **Apache Geode** 和 **Pivotal GemFire** 集成而设计

这是 **Spring Session 的一个重要里程碑版本(Milestone 4)**,专为与 **Apache Geode** 和 **Pivotal GemFire** 集成而设计,支持将用户会话数据存储在分布式内存数据网格中,实现高可用、低延迟的会话管理。该版本适配 Spring Boot 2.2 及更高版本,适用于云原生和微服务架构中的无状态 Web 应用。

[Blog][Domain] programb.blog.csdn.net 483

SpringBoot中集成SpringSession支持多种会话管理器

Spring Session是一个支持实现多种会话管理方案的模块,它可以为Spring应用提供统一的会话管理解决方案,而无需用户自己去实现任何新的功能。本文将结合Spring Boot框架,对Spring Session模块进行详细的介绍和实践。Spring Session对Spring应用的会话管理提供了一种简单易用、统一的方案,而且可以与不同的会话管理机制互相配合,让开发者更加方便地管理会话。

AI天才研究院 2776

JAVA:Spring Session提升分布式Session管理利器

本文探讨了Web应用中会话管理的几种方案及其演进。从传统的单机Web容器会话管理,到Session复制、浏览器存储、Nginx Hash一致性等方案,分析了各自的优缺点。重点介绍了SpringSession的分布式会话解决方案,包括其核心组件、存储方式(Redis/JDBC/内存)、配置实现及多域名共享处理。SpringSession通过将会话数据存储在第三方服务中,实现了跨应用共享、分布式环境下的统一会话管理,具有存储灵活、扩展性强等优势,是当前分布式系统中会话管理的理想选择。

木头 2653

Spring Boot与Spring Session:一招鲜,如何在集群中玩转会话管理的魔法?

Spring Boot与Spring Session的结合,为集群部署的会话管理提供了稳健的解决方案。它简化了配置,强化了数据共享,确保了用户体验的连续性。就像在多维度空间中布下了会话的结界,无论用户如何穿越,都能感受到如一的魔幻体验。现在,你已掌握了这项魔法,去构建你的分布式王国吧,让会话管理如同春风化雨,润物无声。

java专栏 425

基于PCIE8311+FPGA+TMS320F28335 PCIE应用项目开发板PROTEL99设计硬件(原理图+PCB)文件

基于PCIE8311+FPGA+TMS320F28335 PCIE X1应用项目开发板PROTEL99设计硬件(原理图+PCB)文件,Protel 99se 设计的项目工程文件,包括原理图及PCB印制板图,可用Protel或 Altium Designer(AD)软件打开或修改,都已经制板在实际项目中使用,可作为你产品设计的参考。

GJZGRB的博客 581

MATLAB对pcap文件抓包的读取

应用范围 常用的雷达信号,无线网通信信号的格式大多为pcap、wj文件,这里记录一下MATLAB读取pcap文件的方法,具体处理过程及读取协议针对不同的雷达有不同的处理方式,在这里不做说明。 程序 clc;clear;close all; %% 文件位置 filename= 'E:\File\JOB\JOB_1\data.pcap'; fid = fopen(filename,'r'); % 打开包 tmpPack = fread(fid,1350); % 只读前1350个数 读到

诗酒趁年华的博客 3584

基于PLC1200与CB1241的RS485从站Modbus Rtu通信实战指南

本文提供了一份详细的西门子S7-1200 PLC与CB1241 RS485通讯板实现Modbus RTU从站通信的实战指南。内容涵盖从硬件接线、博途软件组态、关键参数设置到程序调试与测试的全过程,重点解析了Modbus_Slave指令配置与数据块映射,帮助工程师快速掌握工业自动化系统中的数据采集与设备接入技术。

Apple的专栏 811

大气层23.0.0整合包升级指南:解决unknow pkg1报错与双系统防误更新

自定义固件(CFW)通过劫持启动流程实现系统接管,其核心在于版本匹配与签名验证。当系统固件更新后,CFW必须同步更新核心文件与签名补丁,否则启动阶段会因版本不匹配而报错。双系统方案中,正版与虚拟系统固件独立,误更新正版系统会导致虚拟系统启动链断裂。正确做法是保持虚拟系统版本不低于正版,并严格对应大气层核心文件与签名补丁。本文围绕大气层23.0.0整合包,详解文件结构、安装顺序、Daybreak固件升级及防误更新策略,助你稳定运行自定义系统。

weixin_32075843的博客 531

麒麟V10 x86_64系统下Qt 5.12.7安装全攻略(附常见报错解决方案)

本文详细介绍了在麒麟V10 x86_64系统上安装Qt 5.12.7的完整流程,包括在线和离线两种安装方案,并提供了常见报错的解决方案。从环境准备到项目配置优化,再到高级调试技巧,全面覆盖Qt开发在国产操作系统上的实践要点,帮助开发者高效搭建开发环境。

weixin_29294395的博客 516

YOLOv12改进策略【独家融合改进】| MobileNetV4+BiFPN,轻松实现降参涨点,适用专栏内所有的骨干替换

可扩展的高效物体检测BiFPN(加权双向特征金字塔网络)

Limiiiing的博客 983

TriCore架构-基于TC397的启动流程

TC397芯片的启动流程分为三个关键阶段:固件启动(BootFirmware)、Bootloader引导和应用程序启动。BootFirmware作为硬件信任根,包含SSW基础初始化、CHSW自检和BSL应急刷写通道。Bootloader承担安全验证和程序引导功能,支持双分区(AB-SWAP)和双引导方案(PBL/SBL)。安全启动通过校验机制确保软件完整性,提供三种可选技术方案。应用程序启动阶段实现软件双分区管理,支持SOTA更新。整个流程体现了汽车电子系统的安全设计理念,通过硬件级保护与软件验证相结合确保

xiandang8023的博客 995

以 Joule 驱动的生成式开发:把需求文档直接变成可运行的 SAP 应用

摘要:SAP BTP的AI助手Joule正在改变开发方式,支持从自然语言描述自动生成数据模型、服务、UI及测试代码。在SAP Business Application Studio中,Joule能根据业务需求生成结构化代码,并提供代码补全、重构、解释等功能。开发者需注意避免上传敏感数据,并对AI生成的代码进行人工审核。Joule特别针对ABAP开发进行了优化,提供符合SAP规范的代码建议,帮助迁移遗留系统。此外,它还能快速生成CAP项目原型,但所有AI生成内容都需经过严格测试验证。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 352

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

上一篇: 【Spring Boot】Lombok,以及 Data 注解的一些说明
下一篇: Spring Boot 缓存
Fala Oviara
博客等级 码龄10年 54粉丝 151原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值