码迷,mamicode.com
首页 > 编程语言 > 详细

Spring系列之——spring security

时间:2019-02-21 00:36:10      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:control   pass   html   app   Servle   play   sping   运行   void   

1 搭建springboot


 

 

2 配置pom依赖(springboot版本为2.1.3)

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

 

3 写一个controller类


 

4 SpringBootApplication中增加注解ComponentScan,并启动

技术图片


 

5 启动测试 http://localhost:8080/index

5.1 开启验证(默认生效),需要输入用户名和密码

  springsecurity默认用户名为user,密码为运行日志中“Using generated security password”,如果需要支持其他用户需要重写抽象类WebSecurityConfigurerAdapter中的configure方法。

技术图片

5.2 关闭验证

  在启动类中排除SecurityAutoConfiguration

技术图片
package com.gbm.myspringboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@ComponentScan(basePackages = {"com.gbm.controller"})
public class MyspingbootApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyspingbootApplication.class, args);
    }
}
View Code

技术图片

Spring系列之——spring security

标签:control   pass   html   app   Servle   play   sping   运行   void   

原文地址:https://www.cnblogs.com/guobm/p/10409780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!