Spring Boot integration with Spring Security
Create a project
For unified management of subsequent projects, a consented parent project, SpringSecurity-Learn, is created here as unified POM dependency management.
Content of the parent POM file
<dependencyManagement>
<! -- Unified management of springboot project engineering -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.17. RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Copy the code
Create a subproject ‘ ‘learning-01’
Project POM files
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<! -- It must be automatically configured -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
</dependencies>
Copy the code
Create springboot application
Create com. Liao. Securtity. Learn01. HelloSecurityApplication. Java file as springboot start classes
@SpringBootApplication
public class HelloSecurityApplication {
public static void main(String[] args) { SpringApplication.run(HelloSecurityApplication.class, args); }}Copy the code
Create test routing com. Liao. Securtity. Learn01. Controller. HelloController. Java file
@RestController
public class HelloController {
@GetMapping("hello")
public String hello(a) {
return "spring security"; }}Copy the code
Creating a Configuration File
resources/application.yml
server:
port: 8001
Copy the code
Open the browser to access to see
The default user name is user
The password is a string of UUids printed on the console
You can customize the user name and password for login
Applicantion.yml is customized in the configuration file
spring:
security:
user:
name: root
password: 123456
Copy the code