当我访问我的 api 时:http://xx/api/v1/reference ,单击 Swagger ,我得到:Unable to infer base url 如何解决这个问题? 在我的类里面,我有:
@Configuration @EnableWebSecurity @Order(1) public class SecurityJavaConfig extends WebSecurityConfigurerAdapter { @Value("${yourapp.http.auth-token-header-name}") private String principalRequestHeader; @Value("${yourapp.http.auth-token}") private String principalRequestValue; @Override protected void configure(HttpSecurity httpSecurity) throws Exception { APIKeyAuthFilter filter = new APIKeyAuthFilter(principalRequestHeader); filter.setAuthenticationManager(new AuthenticationManager() { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String principal = (String) authentication.getPrincipal(); if (!principalRequestValue.equals(principal)) { throw new BadCredentialsException("The API key was not found or not the expected value."); } authentication.setAuthenticated(true); return authentication; } }); httpSecurity. antMatcher("/api/**"). csrf().disable(). sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS). and(). addFilter(filter).authorizeRequests().anyRequest().authenticated(); }
}
我知道已经发布了几个这样的问题: 没有人回答我的问题。显然这在 Springfox 2.8.1-SNAPSHOT 中已修复。谁能给我提供一个适用于 Springfox 2.8.0 的解决方案?
最佳答案
您是否尝试过将以下内容列入白名单?
"/v2/api-docs", "/swagger-resources/configuration/ui", "/swagger-resources", "/swagger-resources/configuration/security", "/swagger-ui.html", "/swagger.json", "/webjars/**"
关于java - 无法推断基本 url - Spring 4.2、Spring Security 4.2、Swagger 2.8.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49183482/