栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringSecurity[01]:初体验SpringSecurity

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringSecurity[01]:初体验SpringSecurity

1、创建SpringBoot项目,并引入SpringSecurity

pom.xml



    4.0.0

    
        org.springframework.boot
        spring-boot-starter-parent
        2.5.5
        
    

    org.example
    spring_security_demo
    1.0-SNAPSHOT

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-security
        
    


2、创建测试类


TestController.java

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class TestController {

    @GetMapping("test")
    public String test() {
        return "hello world";
    }
}
3、启动项目

4、访问测试接口并验证

http://localhost:8080/test

1、浏览器访问http://localhost:8080/test后,页面重定向到了:http://localhost:8080/login。这是因为SpringSecurity默认所有请求必须登录后才可以访问。
2、在未登录状态访问时,页面会重定向到SpringSecurity提供的默认登录页。
3、SpringSecurity默认提供的账号是:user
4、SpringSecurity默认提供的密码是:在应用启动时,控制台会输出的一个由UUID生产的随机密码。在第3步中,用红色框选中部分。
5、点击“Sign in”后,显示测试请求成功

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/859988.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号