springboot集成springsecurity
1.引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2.配置用户名和密码
spring.security.user.name=admin
spring.security.user.password=admin
3.创建一个controller和一个页面
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<body>
<h1>Hello</h1>
<p>我是登录后才可以看的页面</p>
</body>
</html>
package com.yangjunbo.JPADemo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class SecurityController {
@RequestMapping("/")
public String index() {
return "index";
}
}
4.验证测试