0

I have RESTful web service which I have developed in spring boot. I have integrated the swagger2 in my application using Gradle build tool.

testCompile('io.springfox:springfox-swagger2:2.6.1')
testCompile('io.springfox:springfox-swagger-ui:2.6.1')

I wrote the configuration file for swagger2 in following way

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select().apis(RequestHandlerSelectors.basePackage("com.example.restdemo.web"))
                .paths(PathSelectors.any())
                .build();
    }
}

Now when I try to access the http://localhost:8080/v2/api-docs I am getting the JSON string. But when I am trying to access the http://localhost:8080/swagger-ui.html I am not getting Swagger UI view, I am getting the 406 error.

2 Answers2

0

Can you try below Swagger configurations? basePackage is nothing but the entry point of your rest API layer. You can hardcode it in your program.

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    UiConfiguration uiConfig() {
        return new UiConfiguration("validatorUrl", "list", "alpha", "schema",
                UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS, false, true, 60000L);
    }

}
Debopam
  • 3,198
  • 6
  • 41
  • 72
  • even I was having this issue. You mean `@Value("${xyz.abc.myPackage}")` – Govinda Sakhare Oct 25 '17 at 09:49
  • You have to pass the base package to apis. For my case, there were several microservices, so I made it configurable, if you have only one service just pass the base package to .apis(RequestHandlerSelectors.basePackage()) – Debopam Oct 25 '17 at 16:38
  • Updated the answer. Could you please try this config along with whatever you have – Debopam Oct 26 '17 at 18:06
0

Did you try like this? http://localhost:8080/swagger-ui.html#!/test-controller/

Here Controller class name is TestController

Also, replace

.select().apis(RequestHandlerSelectors.basePackage("com.example.restdemo.web"))

with

.select()

As below..

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build();
}