3
votes

I have successfully integrated swagger into my project with

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

I can now hit the url http://localhost:8080/myApp/v2/api-docs and see the json returned describing my REST api. e.g.

{ ? 
   "swagger":"2.0",
   "info":{ ? 
      "description":"Api Documentation",
      "version":"1.0",
      "title":"Api Documentation",
      "termsOfService":"urn:tos",
      "contact":{ ? 

      },
      "license":{ ? 
         "name":"Apache 2.0",
         "url":"http://www.apache.org/licenses/LICENSE-2.0"
      }
   },
   "host":"localhost:8080",
   "basePath":"/myApp",
   "tags":[ ? 
      { ? 
         "name":"staff-controller",
         "description":"Staff Controller"
      },
      { ? 
         "name":"data-controller",
         "description":"Data Controller"
      },
      { ? 
         "name":"master-controller",
         "description":"Master Controller"
      },
      { ? 
         "name":"user-manager-controller",
         "description":"User Manager Controller"
      },
      { ? 
         "name":"client-controller",
         "description":"Client Controller"
      },
      { ? 
         "name":"request-controller",
         "description":"Request Controller"
      }
   ],

I then pulled in the swagger-ui dependency

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

I created a SwaggerConfig bean

@Configuration
@EnableSwagger2
public class SwaggerConfig {

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

and a WebMVCConfig

@EnableWebMvc
public class WebMVCConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}

However when I navigate to http://localhost:8080/myApp/swagger-ui.html I see the swagger header but with no information populated. Screenshot

Is there anything else that I need to configure? Does the Swagger-ui need a path to the root of my project or similar?

My web.xml does have security configured (although I've tried switching this off to no affect)

<servlet>
    <servlet-name>myApp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
                classpath:spring/application.xml
            </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>myApp</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
1
Even I am facing the exact same issue. Can anybody please help! - Akshay Kasar

1 Answers

0
votes

The right url for swagger-ui.html is at http://localhost:8080/swagger-ui.html based on your configuration.