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 doesn't show up for springfox 3.0.0 in Springboot application

See original GitHub issue

I am using Spring boot 2.3.1.RELEASE. My code snippets of SpringFox configuration and main application class are as below:

@Configuration
@EnableWebMvc
public class SpringFoxConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.abc.controllers"))
                .paths(PathSelectors.any())
                .build();
    }
}
@SpringBootApplication
@EnableConfigurationProperties
@PropertySource("classpath:application.properties")
@EnableOpenApi
public class ABCServiceApplication {

    public static void main(String[] args) {
        Installation.init( ABCServiceApplication.class );
        SpringApplication.run(ABCServiceApplication.class, args);
    }
}

Dependency added in build.gradle : “io.springfox:springfox-boot-starter:3.0.0”

I run this application via terminal using following command: java -jar build/libs/abc-application.jar

I can see http://localhost:8080/v3/api-docs working, but swagger ui is not working. Tried accessing http://localhost:8080/swagger-ui/index.html but shows 404. I have tried all possible urls which I saw in documentation and few other sites.

Can someone please help me out here?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

4reactions
Y175commented, Dec 8, 2020

I have similar issue returning 404 while accessing http://localhost:8080/swagger-ui/ . My POM.xml is below

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.0</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-boot-starter</artifactId>
        <version>3.0.0</version>
    </dependency>
<dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-bigquery</artifactId>
        <version>1.116.0</version>
    </dependency>
</dependencies>

My swagger config file


@Configuration
public class SwaggerConfig implements WebFluxConfigurer {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .description("My Reactive API")
                        .title("My Domain object API")
                        .version("1.0.0")
                        .build())
                .enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.comp.pr.demoproj.router"))
                .paths(PathSelectors.any())
                .build();

    }

    @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/");
    }
}

Can someone pls help @IshanDogra @mfvanek ?

you can add this into your swaggerconfig

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

then you can access http://localhost:8080/swagger-ui/index.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

Springfox swagger-ui 3.0.0 does not bring up ... - Stack Overflow
1. add springfox-boot-starter to POM , remove old dependencies from POM: springfox-swagger2 and springfox-swagger-ui · 2. Remove the @ ...
Read more >
Setting up Swagger 3 With Spring Boot - Medium
So let's jump right in to the simple steps: Adding dependencies. Add the 3rd version springfox-boot-starter and springfox-swagger-ui to pom.xml ...
Read more >
Setting Up Swagger 2 with a Spring REST API - Baeldung
In this tutorial, we'll look at Swagger 2 for a Spring REST web service, using the Springfox implementation of the Swagger 2 specification....
Read more >
Springfox Reference Documentation - GitHub Pages
Spring Boot Applications. Remove library inclusions of earlier releases. Specifically remove springfox-swagger2 and springfox-swagger-ui ...
Read more >
failed to start bean 'documentationpluginsbootstrapper ...
I got same issue using springfox-swagger2 and springfox-swagger-ui version(3.0.0), spring-boot version(2.6.2). The way to resolve this issue is by adding ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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