SpringBoot 关闭 Spring Security 自带的默认的 HTTP 登录验证,只需要将 @SpringBootApplication
改成下面的即可
@SpringBootApplication(exclude = { org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class })
例如
package cn.twle.java.demo.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; @ComponentScan("cn.twle.java.demo.demo") @SpringBootApplication(exclude = { org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class }) public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Bean PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(10); } }
目前尚无回复