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

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,那么很有可能会产生冲突,于是项目报错。如下图:

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

解决方法

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

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

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

猜你喜欢

转载自blog.csdn.net/qq_35760825/article/details/129206692