• Spring Security 初体验


    1、首先新建一个 Spring Boot 项目,创建时引入 Spring Security 依赖和 web 依赖

     2、项目创建成功后,我们添加一个测试的 HelloController,内容如下:

    @RestController
    publicclass HelloController {
        @GetMapping("/hello")
        public String hello() {
            return"hello";
        }
    }

    3、接下来什么事情都不用做,我们直接来启动项目。在项目启动过程中,我们会看到如下一行日志:

    Using generated security password: 30abfb1f-36e1-446a-a79b-f70024f589ab

    4、接下来我们去访问 http://localhost:8080/hello 接口,就可以看到自动重定向到登录页面了:

     5、在登录页面,默认的用户名就是 user,默认的登录密码则是项目启动时控制台打印出来的密码,输入用户名密码之后,就登录成功了,登录成功后,我们就可以访问到 /hello 接口了。

  • 相关阅读:
    Combination Sum
    Partition List
    Binary Tree Zigzag Level Order Traversal
    Unique Binary Search Trees II
    Count and Say
    Triangle
    3Sum Closest
    Search for a Range
    Longest Common Prefix
    Convert Sorted List to Binary Search Tree
  • 原文地址:https://www.cnblogs.com/gjq1126-web/p/12987350.html
Copyright © 2020-2023  润新知