1. 添加配置类
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { } }
在给 WebSecutiryConfig 类中加上@EnableWebSecurity 注解后,便会自动被 Spring 发现并注册(查看@EnableWebSecurity 即可看到@Configuration 注解已经存在,所以此处不需要额外添加)。
查看 WebSecurityConfigurerAdapter 类对 configure(HttpSecurity http)的定义。
protected void configure