简体   繁体   中英

How to change Swagger-ui URL?

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?

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();
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM