1.使用maven搭建项目矿建
2.引入依赖
引入spring-boot插件
4.编写启动类以及访问方法
@RestController
@SpringBootApplication
public class SecurityApplication {
@GetMapping("/")
public String hello(){
return "hello spring security";
}
public static void main(String[] args) {
SpringApplication.run(SecurityApplication.class, args);
}
}
通过启动类启动项目 启动成功后,访问页面(http://localhost:8080/) 会看到如下图一样的页面
用户名为user 密码是控制台中打印的一串字符串 登录后看到“hello spring security”
如果自定义用户名和密码 须在application.properties中添加如下的语句
spring.security.user.name=用户名
spring.security.user.password=密码
重新启动就可以使用了