如何在Spring-Boot 2中禁用安全性?

参见英文答案 >
Spring Boot 2.0.x disable security for certain profile                                    4个

在spring-boot-1.x中,我有以下配置来禁用开发模式下的基本安全性:

application.properties:
security.basic.enabled=false

application-test.properties:
security.basic.enabled=true

application-prod.properties:
security.basic.enabled=true

从spring-boot-2.x开始,不再支持该属性.如何实现相同的配置(=禁用默认配置文件中的任何安全相关功能和配置)?

最佳答案 这是配置类.这里允许所有网址:

@Configuration
@ConditionalOnProperty(value = "app.security.basic.enabled", havingValue = "false")
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable()
            .authorizeRequests()
            .antMatchers("/**").permitAll()
            .anyRequest().authenticated();
}
}
点赞