一 创建配置类
在src/main/java目录中,创建SimpleWebSecurityConfig 配置类
package com.pet.demo.config.web;
import org.springframework.context.annotation.Configuration;
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;
@Configuration
@EnableWebSecurity
public class SimpleWebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic()
.and()
.authorizeRequests()
.antMatchers("/","/css/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.permitAll()
.and()