Note: I use Spring Boot 2.0.2, which may not be useful for the 1.5.x series.
If you do not actually use the security function, you can directly remove spring-boot-starter -security depends on
The default user name is user
The password is a string automatically generated when the program starts
You can configure the corresponding user and password in application.properteis
You can also set the corresponding user Name and password
spring.security.user.name=user1
spring.security.user.password=password1
By disabling
package com.yq; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication(scanBasePackages = {"com.yq"}) @EnableAutoConfiguration(exclude = { org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class }) public class WebSecurityDemoApp { private static final Logger log = LoggerFactory.getLogger(WebSecurityDemoApp.class); public static void main(String[] args) { SpringApplication.run(WebSecurityDemoApp.class, args); } }
As long as our Spring Boot project references the following dependencies, the security configuration will be enabled by default.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
If you want to use security but don’t want to enter the user name and password every time, you can disable automatic configuration directly in the Application file
@EnableAutoConfiguration(exclude = { org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class })
Or we can also configure the specified user and password, for example
spring.security.user.name=user1
spring.security.user.password=password1
The above is the detailed content of How to solve the problem that username and password are required to log in to the web page after enabling springboot security. For more information, please follow other related articles on the PHP Chinese website!