question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

swagger-ui endpoint doesn't seem to work

See original GitHub issue

I’m trying to figure out how to get at the Swagger UI using the Springfox artifacts in a Spring Boot MVC application. Unfortunately the reference documentation is rather misleading, since the neither documented endpoint or the (different) endpoint in the screenshot exist in my application.

I’m using the following dependencies in Maven:

<dependency>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-jaxrs</artifactId>
  <version>1.5.0</version>
</dependency>
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
  <version>2.0.1</version>
  </dependency>
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger-ui</artifactId>
  <version>2.0.1</version>
</dependency>

My Docket Bean is very simple for now:

    @Bean
    public Docket myAPI() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .paths(paths())
                .build();
    }

Looking at /mappings in Spring Boot, I have /swagger-resources and /v2/api-docs, but can’t find an endpoint for the UI.

Am I doing something wrong, experiencing a bug, or suffering from bad documentation?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:14
  • Comments:57 (18 by maintainers)

github_iconTop GitHub Comments

25reactions
ghostcommented, May 26, 2016

I have added following in the class where i put @EnableWebMvc annotation. It works fine for me.

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {

       registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

}
17reactions
igilhamcommented, Jun 12, 2015

I have removed the extra swagger 1.5.0 dependency and ensured that I am using the wordnik package names for the API annotations. This appears to make no difference to the resulting behaviour.

My application is defined with the following annotations:

@Configuration
@EnableAutoConfiguration
@ComponentScan
@EnableSwagger2
public class Application {
    // ...
}

I did have an @Configuration class with @EnableWebMvc on it. Removing the @EnableWebMvc annotation seems to fix the missing /swagger-ui.html endpoint. The documentation implies the opposite is true, stating that adding the annotation may fix a NullPointerException.

I had to disable security configurations for various swagger-ui related endpoints to get the UI to load properly, but I got there in the end. Thanks for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Added Springfox Swagger-UI and it's not working, what am I ...
I ran into this issue because I had endpoints with request mappings that had path variables of this form: /{ ...
Read more >
Troubleshooting issues when using Swagger as a REST API ...
Ensure that the following conditions are met: The HTTP server is up and running. The HTTP server can host the HTML file. The...
Read more >
How to Use Swagger Inspector
Signing up (or logging in, if you have an account) allows you to save your call history, pin requests, use collections, and create...
Read more >
Get started with Swashbuckle and ASP.NET Core
Learn how to add Swashbuckle to your ASP.NET Core web API project to integrate the Swagger UI.
Read more >
Show only specific APIs on Swagger — Asp.Net Core - Medium
In this article, I explain how to use Document Filters on Swagger in order to control the endpoints that are being shown on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found