Unable to Infer base URL
See original GitHub issueThis might be one of the most common issues faced with SpringFox with plethora of answers. But I am unable to fix this issue even after following all the usual advice. Details:
I am using Spring Boot: v2.0.3.RELEASE and Spring Fox: v2.9.2
Spring Security Config:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
private UserDetailsService userDetailsService;
private BCryptPasswordEncoder bCryptPasswordEncoder;
private SecurityProperties securityProperties;
private AppProperties AppProperties;
public WebSecurityConfig(UserDetailsService userDetailsService,
BCryptPasswordEncoder bCryptPasswordEncoder,
SecurityProperties securityProperties,
AppProperties AppProperties) {
this.userDetailsService = userDetailsService;
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
this.securityProperties = securityProperties;
this.AppProperties = AppProperties;
}
@Configuration
@Order(1)
public class BasicAuthenticationConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/admin/**")
.csrf().disable()
.httpBasic().and()
.authorizeRequests().anyRequest().hasRole("ADMIN").and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser(AppProperties.getAdminUsername())
.password(bCryptPasswordEncoder.encode(AppProperties.getAdminPassword()))
.roles("ADMIN");
}
}
@Configuration
@Order(2)
public class TokenAuthenticationConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.
cors().and().csrf().disable()
.authorizeRequests()
.antMatchers("/no-auth/**").permitAll()
.anyRequest().authenticated()
.and()
.addFilter(new JWTAuthenticationFilter(securityProperties, authenticationManager()))
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/v2/api-docs", "**/swagger-resources/**", "/swagger-ui.html", "/webjars/**")
.antMatchers(HttpMethod.OPTIONS, "/**");
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
}
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.applyPermitDefaultValues();
corsConfiguration.setAllowedOrigins(Collections.singletonList("*"));
corsConfiguration.setAllowedMethods(Arrays.asList("GET", "POST", "DELETE"));
corsConfiguration.setMaxAge(3600L);
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", corsConfiguration);
return source;
}
}
}
Springfox Config:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Autowired
private AppProperties AppProperties;
@Bean
public WebMvcConfigurer mvcConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
};
}
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("foo-api")
.apiInfo(apiInfo())
.useDefaultResponseMessages(false)
.produces(Collections.singleton("application/json"))
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Foo API")
.termsOfServiceUrl(AppProperties.getApiTosUrl())
.version("1.0").build();
}
}
Visiting: http://127.0.0.1:8080/swagger-ui.html
Displays:
Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually:
Repeatedly clicking Ok in the popup doesn’t help.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Why does springfox-swagger2 UI tell me "Unable to infer base ...
I had this annotation in the SwaggerConfig class but the "Unable to infer base URL" error persisted. When I moved this annotation to...
Read more >Swagger ui stuck on unable to infer base url · Issue #1996
When I try to set the base url through this message, no matter what I enter, the dialog flickers and just stands there....
Read more >[SpringFox Error] Unable to infer base url - Taogen's Blog
Solution. make sure your swagger configuration is under your spring boot application which can be scanned. and then it solved.
Read more >Swagger UI Configuration with OKTA - Okta Support
Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The...
Read more >Unable to infer base url in Swagger 2.9.2-eclipse
Coding example for the question Swagger UI - Unable to infer base url in Swagger ... app with embedded tomcat then you need...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Spring Boot 2.1.1.RELEASE with spring fox 2.9.2, I am encountering the same issue, I will paste the log entries(DEBUG) when trying to load the http://localhost:8890/swagger-ui.html:
It seems the PropertySourcedRequestMappingHandlerMapping [lookupHandlerMethod] fails to find the handler methods for those endpoints, still trying to make this work.
Now the output from another Spring Boot application (same versions as above), where the swagger ui is functioning:
This issue has been automatically closed because it has not had recent activity. Please re-open a new issue if this is still an issue.