开发者

解决springSecurity 使用默认登陆界面登录后无法跳转问题

开发者 https://www.devze.com 2023-12-06 10:26 出处:网络 作者: D.....
项目环境:springboot下使用springSecurity 版本2.7.8 解决:可能是controller中使用的路径为login,在没有学配置文件情况下。

项目环境:springboot下使用springSecurity 版本2.7.8

解决:可能是controller中使用的路径为login,在没有学配置文件情况下。

//正确使用
    @RequestMapping("/hello")
    public String login(){
        return "登录成功";
    }
//    错误的使用
    @RequestMapping("/login")
 编程   public String errologin(){
        return "登录成功";

如果使用login作为请求路径的话,就会和springSecurity的默认路径冲突,springSecurity默认的登录页面路径就是 /login。这是在没有写任何配置的情况下。想解决就别用login或者自己设置配置文件来更改。

下面是完整的springSecurity的案例

Controller

@RestController
public class loginController {
//正确使用
    @RequestMapping("/编程客栈hello")
    public String login(){
        return "登录成功";
    }
}    

pom

<dependencies&http://www.devze.comgt;
//不用写版本 依赖的版本自动和父版本匹配
        <dependency>
            <groupId>org.www.devze.comspringframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifjsactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
</dependencies>

然后就是可以直接启动项目 登录界面

默认的用户名user

默认密码是控制台输出的

解决springSecurity 使用默认登陆界面登录后无法跳转问题

密码

解决springSecurity 使用默认登陆界面登录后无法跳转问题

到此这篇关于springSecurity 使用默认登陆界面登录后无法跳转的文章就介绍到这了,更多相关springSecurity 界面登录无法跳转内容请搜索编程客栈(www.devze.com)以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程客栈(www.devze.com)!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号