点击上方“Java知音”,选择“置顶公众号”
技术文章第一时间送达!
作者:小LUA
cnblogs.com/LUA123/p/9337963.html
在单机版的Springboot+Shiro的基础上,这次实现共享Session。
这里没有自己写RedisManager、SessionDAO。用的 crazycake 写的开源插件
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
redis配置文件
package com.example.demo.conf;
Shiro配置文件
package com.example.demo.conf;
UserService
package com.example.demo.service;
impl
package com.example.demo.service.impl;
controller
package com.example.demo.controller;
redis.properties
shiro.redis.host=localhost:6379
shiro.redis.timeout=1800000
applicatin.properties
#server.port=8080
server.port=8081
#server.port=8082
spring.redis.host=127.0.0.1
spring.redis.port=6379
index.html
html>
home.html
html>
以上两种配置各打包一次(记得留着打包好的jar包)
http://nginx.org/
解压到无中文目录,修改Nginx配置文件
upstream myapp{
server 127.0.0.1:8081 weight=1;
server 127.0.0.1:8082 weight=1;
}
server{
listen 80;
server_name myapp;
location / {
proxy_pass http://myapp;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
到此,先启动两个jar包(分别是8081,Node-One;8082,Node-Two)
然后启动Nginx
浏览器访问:http://localhost/
刷新看看..
..
随便在一个节点上注册,登录,然后刷新到另外一个节点,发现不用登录就可以访问权限资源
..
GitHub
https://github.com/Mysakura/boot-shiro-session
推荐阅读(点击即可跳转阅读)
1.SpringBoot内容聚合
2.面试题内容聚合
3.设计模式内容聚合
4.Mybatis内容聚合
5.多线程内容聚合
觉得不错?欢迎转发分享给更多人
我知道你 “在看”