您可以做的一件事是有两个
WebSecurityConfigurerAdapters:
@EnableWebSecurity@Order(Ordered.HIGHEST_PRECEDENCE)class FirstEndpointConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) { http .requestMatchers() .antMatchers("/specialendpoint") .and() .authorizeRequests() .anyRequest().authenticated() .and() .httpBasic(); } @Override protected void configure(AuthenticationManagerBuilder auth) { auth.userDetailsService(); }}@Configurationclass SecondEndpointConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) { http // all other requests handled here .authorizeRequests() .anyRequest().authenticated() .and() .httpBasic(); } @Override protected void configure(AuthenticationManagerBuilder auth) { auth.userDetailsService(); }}requestMatchers()用于将
springSecurityFilterChains 定位到特定端点。



