SpringSecurity之搭建简单的security服务

最近想要把SpringSecurity巩固一下,按黑马的视频学习,SpringSecurity黑马程序员全套教程,从入门到精通(IDEA版)超完整教程,手把手教学_哔哩哔哩_bilibili

一、创建工程并导入依赖

先搭建springboot工程

  • pom.xml

<parent>
        <artifactId>spring-boot-starter-parent</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>2.1.3.RELEASE</version>
    </parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
  • controller

@RestController
@RequestMapping("product")
public class ProductController {
    @GetMapping("/test")
    public String test(){
        return "sucess";
    }

}

二、加入SpringSecurity

1.引入security依赖

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

2.启动服务

  • 访问后端服务,发现跳转到了登录页面

  •  这是因为SpringSecurity默认实现是拦截器链,对我们进行了拦截,需要我们登录,登录名默认是 user,密码是自己启动后台服务时候控制台打印的。

  •  登陆成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值