I am working on a SpringBoot based REST Api and using Springfox to generate the swagger docs.
Here is the Swagger configuration:
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Autowired
private AppConfiguration appConfiguration;
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("app-api")
.apiInfo(apiInfo())
.select()
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("App API")
.termsOfServiceUrl(appConfiguration.getApiTosUrl())
.version("1.0").build();
}
}
And here is the web security configuration I am using:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable().authorizeRequests()
.antMatchers("/no-auth/**").permitAll()
.antMatchers("/v2/api-docs", "/swagger-resources/configuration/ui", "/swagger-resources", "/swagger-resources/configuration/security", "/swagger-ui.html", "/webjars/**").permitAll()
.anyRequest().authenticated()
.and()
.addFilter(new JWTAuthenticationFilter(securityConfiguration, authenticationManager()))
// this disables session creation on Spring Security
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
}
@Bean
CorsConfigurationSource corsConfigurationSource() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
return source;
}
Visiting the url: http://localhost:8080/swagger-ui.html throws up HTTP error 405: GET request not supported.
Although I can visit the url: http://localhost:8080/v2/api-docs?group=app-api
I have scoured the web to find a resolution but I am not getting why this is happening.
You may instruct me on how to resolve this issue.
EDIT: I noticed that swagger-ui.htm is not being mapped at all! I am using springfox 2.8.0
2018-05-14 12:17:47.019 INFO 1012 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources]}" onto public org.springframework.http.ResponseEntity> springfox.documentation.swagger.web.ApiResourceController.swaggerResources() 2018-05-14 12:17:47.020 INFO 1012 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources/configuration/ui]}" onto public org.springframework.http.ResponseEntity springfox.documentation.swagger.web.ApiResourceController.uiConfiguration() 2018-05-14 12:17:47.021 INFO 1012 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources/configuration/security]}" onto public org.springframework.http.ResponseEntity springfox.documentation.swagger.web.ApiResourceController.securityConfiguration() 2018-05-14 12:17:47.026 INFO 1012 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)