2

I have tried to change the swagger URL, right now i have "http://localhost:8080/context-root/rest/swagger-ui.html", i want it to be "http://localhost:8080/swagger". I tried using the DOCKET.Host("swagger"), but browser is spinning. And its not loading screen.

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.4.0</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.4.0</version>
    </dependency>

Can any one help with that?

prathap
  • 21
  • 1
  • 2

1 Answers1

0

Have you tried Path Provider ?

    @Configuration
    @EnableSwagger2
    @Profile({"!production"})   
     public class SwaggerConfiguration extends WebMvcConfigurerAdapter {


        @Autowired
        private ServletContext servletContext;

        @Bean
        public Docket api() {

            return new Docket(DocumentationType.SWAGGER_2)
                    .host("localhost")
                    .pathProvider(new RelativePathProvider(servletContext) {
                        @Override
                        public String getApplicationBasePath() {
                            return "/swagger";
                        }
                    })
                    .protocols(new HashSet<String>(Arrays.asList(protocols)))
                    .select()
                    .apis(RequestHandlerSelectors.any())
                    .paths(PathSelectors.any())
                    .build();
        }
    }
mh377
  • 1,656
  • 5
  • 22
  • 41