0

I have spring (not spring boot) application with springfox3. Application swagger url is working fine.

I have to migrate from springfox to springdoc-openapi. I have implemented all migration steps mentioned in below url.

https://springdoc.org/migrating-from-springfox.html

My application swagger url is not working after migrating to springdoc-swagger. Swagger url - http://server:port/context/swagger-ui.html

Can anyone please help me what i am doing wrong. TIA

My changes are as below:

  1. Removed springfox dependency and added below in gradle:

compile ("org.springdoc:springdoc-openapi-ui:1.6.11")

  1. Commented single Docket and added below in application.properties file:

springdoc.packagesToScan=package

springdoc.pathsToMatch=/v1, /api/**

  1. Added below OpenAPI bean:

@Bean public OpenAPI springShopOpenAPI() {

      return new OpenAPI()

              .info(new Info().title("SpringShop API")
              .description("Spring shop sample application")
              .version("v0.0.1")
              .license(new License().name("Apache 2.0").url("http://springdoc.org")))
              .externalDocs(new ExternalDocumentation()
              .description("SpringShop Wiki Documentation")
              .url("https://springshop.wiki.github.org/docs"));
  }
  1. I also had below config for springfox. I have done minor url change for opeanapi.

public class Config implements WebMvcConfigurer {

@Override
public void addResourceHandlers(ResourceHandlerRegistry theRegistry) {
    
    theRegistry.
        addResourceHandler("/swagger-ui/**")
        //.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/") --> springfox
        .addResourceLocations("classpath:/META-INF/resources/")  --> updated for springdoc
        .resourceChain(false);
}

@Override
public void addViewControllers(ViewControllerRegistry theRegistry) {
    theRegistry.addViewController("/swagger-ui/")
        .setViewName("forward:" + "/swagger-ui/index.html");
}

Thanks

Sachin
  • 29
  • 2

0 Answers0