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"
骑着母猪去打猎的备忘录,如有侵权请联系本人骑着母猪去打猎删除。https://www.cnblogs.com/shichq/p/19120051
如果本文对您有所帮助,麻烦在下面评论里面随便敲上那么几下键盘,谢谢了