Sa-token: error on line 1 at column 48: Extra content at the end of the document

分手后的思念是犯贱 2023-10-04 22:04 123阅读 0赞

This page contains the following errors:: error on line 1 at column 48: Extra content at the end of the document

文章目录

    • 问题产生原因
    • 解决方法

今天在尝试开源登录项目 Sa-token 时,按照官方文档要求引入Sa-Token-Quick-Login 快速登录认证登录页时,项目报错,如下:This page contains the following errors: error on line 1 at column 48: Extra content at the end of the document
在互联网上查询了许久都没有问题的产生原因与解决方法,遂写下此篇文章。


问题产生原因

  在引入 Sa-Token-Quick-Login 后,Sa-token 自身的路由拦截规则会发生改变,如果你之前私自在项目中配置过路由拦截 SaRouter,那么很有可能会产生冲突,于是项目报错。如下图:

  1. @Configuration
  2. public class SaTokenConfigure implements WebMvcConfigurer {
  3. @Override
  4. public void addInterceptors(InterceptorRegistry registry) {
  5. // 注册 Sa-Token 拦截器,定义详细认证规则
  6. registry.addInterceptor(new SaInterceptor(handler -> {
  7. // 路由拦截规则
  8. SaRouter.match("/**")
  9. .notMatch("/user/doLogin", "/","/index")
  10. .check(r -> StpUtil.checkLogin());
  11. })
  12. ).addPathPatterns("/**");
  13. }
  14. }

解决方法

注释掉原先代码中编写的路由拦截规则SaRouter即可。

  1. @Configuration
  2. public class SaTokenConfigure implements WebMvcConfigurer {
  3. @Override
  4. public void addInterceptors(InterceptorRegistry registry) {
  5. // 注册 Sa-Token 拦截器,定义详细认证规则
  6. registry.addInterceptor(new SaInterceptor(handler -> {
  7. // SaRouter.match("/**")
  8. // .notMatch("/user/doLogin", "/","/index")
  9. // .check(r -> StpUtil.checkLogin());
  10. })
  11. ).addPathPatterns("/**");
  12. }
  13. }

项目成功运行
Sa-token登录页

发表评论

表情:
评论列表 (有 0 条评论,123人围观)

还没有评论,来说两句吧...

相关阅读