首页 > 其他分享 >修改sa-token检查token的报错信息

修改sa-token检查token的报错信息

时间:2023-12-01 16:11:31浏览次数:39  
标签:自定义 springframework token 报错 import sa com public

1.创建一个类去实现 NotLoginExceptionMapper

import cn.dev33.satoken.exception.NotLoginException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype
@Component
public class CustomNotLoginExceptionMapper implements NotLoginExceptionMapper {

@Override
public ResponseEntity<Object> toResponse(NotLoginException e) {
// 自定义处理逻辑,例如返回自定义的错误信息或进行其他操作
String errorMessage = "您没有登录";
return new ResponseEntity<>(errorMessage, HttpStatus.UNAUTHORIZED);
}
}

2.启动类添加注解确保自定义的类可以被扫描到

@ComponentScan("com.example") // com.example替换为上面那个类的包路径

3.将之作为bean在启动类注册

@SpringBootApplication
@ComponentScan("com.example")
public class YourApplication {

public static void main(String[] args) {
SpringApplication.run(YourApplication.class, args);
}

@Bean
public CustomNotLoginExceptionMapper customNotLoginExceptionMapper() {
return new CustomNotLoginExceptionMapper();
}

}

 

标签:自定义,springframework,token,报错,import,sa,com,public
From: https://www.cnblogs.com/baoguiying/p/17869944.html

相关文章

  • ubuntu编译软件报错:fatal error: libnet.h: No such file or directory
    参考:https://blog.csdn.net/wuyou1995/article/details/104742326/  ---------------------------------------     解决方法:sudoapt-getinstalllibnet1-dev ......
  • 关于解决vue报错"Problems loading reference 'https://schemastore.azurewebsites.ne
    打开setting时会看到有一条三角形的警告信息 看问题描述:无法从该网站加载解决方法:打开设置,找到扩展下的json项 设置之后可以在settings.json文件中看到新增加一项 "json.schemaDownload.enable":false可以直接在界面上设置: "json.schemaDownload.enable":false......
  • MAUI+Masa Blazor APP 各大商店新手发布指南-华为篇
    目录前言准备材料一、企业认证二、审核资料审核注意事项总结前言AppGalleryConnect(简称AGC)是华为应用市场推出的应用一站式服务平台,致力于为开发者提供应用创意、开发、分发、运营、分析全生命周期服务,构建全场景智慧化的应用生态。AppGalleryConnect深度整合华为内部各项优......
  • Elastic Universal Profiling
    ElasticObservability8.10introducesthegeneralavailabilityreleaseofElasticUniversalProfiling™ andenhancementstotheElasticAIAssistantforObservability.Elastic® UniversalProfilingisawhole-system,always-on,continuousprofilingsolution......
  • RestTemplate连续读取两个不同文件时报错Read timed out
    在项目上负责对接一些三方接口,鉴于之前的经验,选择使用RestTemplate来实现各种http请求,以及文件的读取。首先写了RestTemplate的配置类来配置基础信息,代码如下:@Configuration@ConditionalOnClass(value={RestTemplate.class,HttpClient.class})publicclassRestTemplateCo......
  • vue报错export 'default' (imported as 'VueRouter') was not found in 'vue-route
    直接使用npminstallvue-router-save安装的路由,运行报错 经排查后发现是安装的vue-router版本太高使用npmuninstallvue-router卸载之前安装的路由使用[email protected]安装低版本的路由问题解决!!! ......
  • Mysql连接报错解决方案
    错误:Readingfromthestreamhasfailed.解决方案1:添加SslMode=None解决方案2:找到开始菜单下mysql目录下的cmd程序,如图: 1、数据库用户的加密方式里已经是mysql_native_password,但远程链接时依旧提示Authenticationtohost"11.xx.x.xxxforuser’ejdwhwdas’usingmethod......
  • [Jenkins]在windows slave上执行svn命令报错
    jenkins在windowsslave上执行svn命令报错"svn:E170001:Can'tgetusernameorpassword"原文:https://jianghaitao1221.github.io/2016/08/16/jenkins-windows-svn-name-pwd-not-fount/现象#jenkins上执行svn命令svnup报错如下:svn:E170013:Unabletoconnectt......
  • SAP PO 接口配置1:连通WebService-通过PO调用第三方接口
    背景说明SAP通过PO中间件进行接口调用,调用外部接口。外部接口可以用任意方式生成,常见的REST类型接口即可,关于如何使用python生成接口,其他章节另述。本教程的前置条件,PO中已配置BusinessSystems,并与SAP环境连通。1.测试接口这里以常见的post接口做示例,如有其他类型接口,需......
  • 在eclipse中拖动项目到Tomcat服务器中报错:Project facet Java version 16 is not supp
    ......