springSecurity简单拦截
一、引入pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
二、配置文件 - - - 设置默认用户名密码
spring:
security:
user:
name: root
password: root
三、配置类
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/index/**").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic().and()
.csrf().disable();
}
}