当前位置: 首页 > news >正文

Tomcat使用redis管理session

Tomcat使用redis管理session

server.xml

<!-- GlobalNamingResources节点中添加新的Resource节点 --><GlobalNamingResources><!-- Editable user database that can also be used byUserDatabaseRealm to authenticate users--><Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/><!-- tomcat session 共享 --><Resource auth="Container" closeMethod="shutdown" configPath="${catalina.base}/conf/redisson.yaml" factory="org.redisson.JndiRedissonFactory" name="bean/redisson"/></GlobalNamingResources>

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements.  See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License.  You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
--><!-- The contents of this file will be loaded for each web application --><Context><!-- Default set of monitored resources. If one of these changes, the    --><!-- web application will be reloaded.                                   --><WatchedResource>WEB-INF/web.xml</WatchedResource><WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource><WatchedResource>${catalina.base}/conf/web.xml</WatchedResource><!-- Uncomment this to disable session persistence across Tomcat restarts --><!--<Manager pathname="" />--><!-- 添加以下两个节点 --><ResourceLink name="bean/redisson"global="bean/redisson"type="org.redisson.api.RedissonClient"/><Manager className="org.redisson.tomcat.JndiRedissonSessionManager"readMode="REDIS"jndiName="bean/redisson"/>
</Context>

在server.xml,context.xml同级目录里面,也就是/tomcat/conf/目录内,添加文件redisson.yaml

其中password,address按照系统配置书写

singleServerConfig:idleConnectionTimeout: 10000connectTimeout: 10000timeout: 3000retryAttempts: 3retryInterval: 1500password: xxxxxxsubscriptionsPerConnection: 5clientName: nulladdress: "redis://127.0.0.1:6379"subscriptionConnectionMinimumIdleSize: 1subscriptionConnectionPoolSize: 50connectionMinimumIdleSize: 24connectionPoolSize: 64database: 0dnsMonitoringInterval: 5000
threads: 16
nettyThreads: 32
codec: !<org.redisson.codec.MarshallingCodec> {}
transportMode: "NIO"

 

http://www.hskmm.com/?act=detail&tid=21258

相关文章:

  • NOC片上网络总线初探
  • AT_agc037_c [AGC037C] Numbers on a Circle
  • 记账本|基于SSM的家庭记账本小程序设计与实现(源码+数据库+文档) - 实践
  • redis数据连接写法
  • 缩放 div
  • 死锁的概念
  • 【2025-09-29】团队合作
  • 杂凑算法学习笔记
  • pg库支持扩展postgis
  • kuboard部署启用3个etcd(k8s单个master)
  • 数据库服务分布架构(MyCAT)
  • 题解:P14038 [PAIO 2025] Adventure Plan
  • 20231414_王仕琪_密码技术密码杂凑算法学习笔记
  • web3D、webGL、webGPU、webGIS、webXR、webCodecs的概念和对比 - 实践
  • Claude code的 thinking on/off差别有多少
  • Ubuntu 25的网络配置
  • 2025.9.26 测试
  • 贝叶斯学习笔记 - 详解
  • Ubuntu 24和25配置apt国内源
  • 实用指南:AWS实战:轻松创建弹性IP,实现固定公网IP地址
  • 完整教程:自然语言处理项目之情感分析(下)
  • 还在为安装PS发愁?这款网页版工具,打开浏览器就能用!
  • 委托相关
  • 清除“请允许观看视频”通知页面的完整指南
  • 千亿芯片公司被股东“抛弃” ,AI芯片第一股前景几何?
  • Java 与智慧港口:航运调度与物流枢纽数字化
  • DeepSeek-V3.2-Exp 发布,训练推理提效,API 同步降价
  • 图片任意切割工具(Python 3.8 实现)
  • 从零构建能自我优化的AI Agent:Reflection和Reflexion机制对比详解与实现
  • 超精简的小型C编译器