refactor: 重构所有 rpc 组件的 SaTokenContext 上下文读写策略 & 删除二级上下文模块

This commit is contained in:
click33
2025-04-07 05:41:30 +08:00
parent c6a081ebf6
commit 3acc7bd7af
50 changed files with 526 additions and 585 deletions

View File

@@ -1,32 +1,33 @@
package com.pj.more;
package com.pj.controller;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.pj.service.DemoService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.dev33.satoken.stp.StpUtil;
@RestController
public class TestController {
@DubboReference
private DemoService demoService;
// Consumer端登录状态传播到Provider端
// Consumer端登录状态传播到Provider端 --- http://localhost:8081/test
@RequestMapping("test")
public String test() {
public SaResult test() {
demoService.isLogin("----------- 登录前 ");
StpUtil.login(10001);
demoService.isLogin("----------- 登录后 ");
return "ok";
return SaResult.ok();
}
// Provider端登录状态回传到Consumer端
// Provider端登录状态回传到Consumer端 --- http://localhost:8081/test2
@RequestMapping("test2")
public String test2() {
public SaResult test2() {
System.out.println("----------- 登录前 ");
System.out.println("Token值" + StpUtil.getTokenValue());
System.out.println("是否登录:" + StpUtil.isLogin());
@@ -35,38 +36,38 @@ public class TestController {
System.out.println("----------- 登录后 ");
System.out.println("Token值" + StpUtil.getTokenValue());
System.out.println("是否登录:" + StpUtil.isLogin());
return "ok";
System.out.println("是否登录:" + StpUtil.isLogin());
return SaResult.ok();
}
// Consumer端登录状态在Consumer端保持
// Consumer端登录状态在Consumer端保持 --- http://localhost:8081/test3
@RequestMapping("test3")
public String test3() {
public SaResult test3() {
System.out.println("----------- 登录前 ");
System.out.println("Token值" + StpUtil.getTokenValue());
System.out.println("是否登录:" + StpUtil.isLogin());
System.out.println("Token值" + StpUtil.getTokenValue());
System.out.println("是否登录:" + StpUtil.isLogin());
StpUtil.login(10003);
demoService.isLogin("----------- Provider状态");
System.out.println("----------- 登录后 ");
System.out.println("Token值" + StpUtil.getTokenValue());
System.out.println("是否登录:" + StpUtil.isLogin());
return "ok";
System.out.println("Token值" + StpUtil.getTokenValue());
System.out.println("是否登录:" + StpUtil.isLogin());
return SaResult.ok();
}
// Provider端登录状态在Provider端保持
// Provider端登录状态在Provider端保持 --- http://localhost:8081/test4
@RequestMapping("test4")
public String test4() {
public SaResult test4() {
// 登录
demoService.doLogin(10004);
// 打印一下
demoService.isLogin("----------- 会话信息 ");
return "ok";
return SaResult.ok();
}
}

View File

@@ -0,0 +1,28 @@
package com.pj.controller;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.pj.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@Autowired
private DemoService demoService;
// test
@RequestMapping("test")
public SaResult test() {
demoService.isLogin("----------- 登录前 " + StpUtil.isLogin());
StpUtil.login(10001);
demoService.isLogin("----------- 登录后 " + StpUtil.isLogin());
return SaResult.ok();
}
}

View File

@@ -1,11 +1,12 @@
package com.pj.more;
package com.pj.controller;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.pj.service.DemoService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.dev33.satoken.stp.StpUtil;
@RestController
public class TestController {
@@ -14,19 +15,19 @@ public class TestController {
// Consumer端登录状态传播到Provider端
@RequestMapping("test")
public String test() {
public SaResult test() {
demoService.isLogin("----------- 登录前 ");
StpUtil.login(10001);
demoService.isLogin("----------- 登录后 ");
return "ok";
return SaResult.ok();
}
// Provider端登录状态回传到Consumer端
@RequestMapping("test2")
public String test2() {
public SaResult test2() {
System.out.println("----------- 登录前 ");
System.out.println("Token值" + StpUtil.getTokenValue());
System.out.println("是否登录:" + StpUtil.isLogin());
@@ -35,14 +36,14 @@ public class TestController {
System.out.println("----------- 登录后 ");
System.out.println("Token值" + StpUtil.getTokenValue());
System.out.println("是否登录:" + StpUtil.isLogin());
return "ok";
System.out.println("是否登录:" + StpUtil.isLogin());
return SaResult.ok();
}
// Consumer端登录状态在Consumer端保持
@RequestMapping("test3")
public String test3() {
public SaResult test3() {
System.out.println("----------- 登录前 ");
System.out.println("Token值" + StpUtil.getTokenValue());
System.out.println("是否登录:" + StpUtil.isLogin());
@@ -52,21 +53,21 @@ public class TestController {
System.out.println("----------- 登录后 ");
System.out.println("Token值" + StpUtil.getTokenValue());
System.out.println("是否登录:" + StpUtil.isLogin());
return "ok";
System.out.println("是否登录:" + StpUtil.isLogin());
return SaResult.ok();
}
// Provider端登录状态在Provider端保持
@RequestMapping("test4")
public String test4() {
public SaResult test4() {
// 登录
demoService.doLogin(10004);
// 打印一下
demoService.isLogin("----------- 会话信息 ");
return "ok";
return SaResult.ok();
}
}

View File

@@ -0,0 +1,28 @@
package com.pj.controller;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.pj.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@Autowired
private DemoService demoService;
// test
@RequestMapping("test")
public SaResult test() {
demoService.isLogin("----------- 登录前 " + StpUtil.isLogin());
StpUtil.login(10001);
demoService.isLogin("----------- 登录后 " + StpUtil.isLogin());
return SaResult.ok();
}
}