springfox: Springfox swagger-ui.html not loading using version 3.0.0-SNAPSHOT

In our project we are using 3.0.0-SNAPSHOT of swagger springfox.

Recently when we open swagger-ui.html, it is giving 404 Whilte Label Error.

I enabled logs at web level

`

logging.level.web=TRACE
logging.level.org.springframework.web=TRACE

`

It is loading “/swagger-resources”, but not loading “/swagger-ui.html”

The addition of the resource handler is as per the document.

When loading “/swagger-ui.html”, it’s giving “Resource not found”

`

web.server.adapter.HttpWebHandlerAdapter.traceDebug - [74c4396b] HTTP GET "/swagger-resources/", headers={masked}
web.reactive.result.method.annotation.RequestMappingHandlerMapping.lambda$getHandler$1 - [74c4396b] Mapped to public org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> springfox.documentation.swagger.web.ApiResourceController.swaggerResources()
web.reactive.result.method.annotation.ResponseEntityResultHandler.selectMediaType - Using 'application/json;q=0.8' given [text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8] and supported [application/json]
web.reactive.result.method.annotation.ResponseEntityResultHandler.writeBody - [74c4396b] 0..1 [java.util.List<springfox.documentation.swagger.web.SwaggerResource>]
http.codec.json.Jackson2JsonEncoder.trace - [74c4396b] Encoding [[springfox.documentation.swagger.web.SwaggerResource@4903f26e, springfox.documentation.swagger.web.SwaggerResource@57b46085, springfox.documentation.swagger.web.SwaggerResource@4beb0f82, springfox.documentation.swagger.web.SwaggerResource@3a6db652, springfox.documentation.swagger.web.SwaggerResource@6caba3f3, springfox.documentation.swagger.web.SwaggerResource@18ef56ab, springfox.documentation.swagger.web.SwaggerResource@b6bcd2b, springfox.documentation.swagger.web.SwaggerResource@5ce32532, springfox.documentation.swagger.web.SwaggerResource@6d66b166, springfox.documentation.swagger.web.SwaggerResource@fdef86f, springfox.documentation.swagger.web.SwaggerResource@5a096e2a, springfox.documentation.swagger.web.SwaggerResource@1f060aec, springfox.documentation.swagger.web.SwaggerResource@473365eb, springfox.documentation.swagger.web.SwaggerResource@3fd6e0e2]]
web.server.adapter.HttpWebHandlerAdapter.traceDebug - [74c4396b] Completed 200 OK, headers={masked}
http.server.reactive.ReactorHttpHandlerAdapter.trace - [74c4396b] Handling completed

web.server.adapter.HttpWebHandlerAdapter.traceDebug - [74c4396b] HTTP GET "/swagger-ui.html", headers={masked}
web.reactive.handler.SimpleUrlHandlerMapping.lookupHandler - [74c4396b] Matching patterns [/swagger-ui.html**, /**]
web.reactive.handler.SimpleUrlHandlerMapping.lambda$getHandler$1 - [74c4396b] Mapped to ResourceWebHandler ["classpath:/META-INF/resources/"]
web.reactive.resource.ResourceWebHandler.lambda$handle$0 - [74c4396b] Resource not found
web.reactive.function.server.RouterFunctions.route - [74c4396b] Matched org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorWebExceptionHandler$$Lambda$1372/0x00000008008bb040@10209892
web.HttpLogging.debug - [74c4396b] Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /swagger-ui.html
core.codec.CharSequenceEncoder.trace - [74c4396b] Writing "<html><body><h1>Whitelabel Error Page</h1><p>This application has no configured error view, so you are seeing this as a fallback.</p><div id='created'>Thu Jul 02 22:15:45 IST 2020</div><div>There was an unexpected error (type=Not Found, status=404).</div></body></html>"
web.server.adapter.HttpWebHandlerAdapter.traceDebug - [74c4396b] Completed 404 NOT_FOUND, headers={masked}
http.server.reactive.ReactorHttpHandlerAdapter.trace - [74c4396b] Handling completed

`

I checked if path inside META-INF is changed or not as per documentation at https://springfox.github.io/springfox/docs/snapshot/#snapshot-3, it is same as V 2.10.5

Then, when I changed version from V 3 Snapshot to current stable 2.10.5, it worked.

Can you let me know what I am missing? And since I am a noobie, can you tell me is snapshot version is like beta version which should not be used in production?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 25 (3 by maintainers)

Commits related to this issue

Most upvoted comments

In spring boot it works by simply adding this, no other dependencies needed: <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency> The url is /swagger-ui/ , mind the final slash.

I use 3.0.0 and find the new swagger ui is http://xxxx:port/swagger-ui/ ( please remember the last splash). actually, you can add spring-boot-starter-actuator and confirm the swagger ui mapping by check http://xxx:port/actuator/mappings . And my suggestion is restore the url to swagger-ui.html.

Hi @dilipkrish I have added below mentioned code in class WebSecurityConfiguration extends WebSecurityConfigurerAdapter

void configure(final WebSecurity web) { web.ignoring().antMatchers('/v2/api-docs', '/swagger-resources/**', '/swagger-ui/**', '/swagger-ui/index.html**', '/webjars/**', '/actuator/health')

but still getting same error

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

Hello, I added this dependency to pom.xml (this is the only dependency pointing to sprinfox) and still getting error while accessing /swagger-ui/. On the other hand v2/api-docs works well. I didn’t create any configuration classes. Does anyone know, what can be wrong here? Any pointers are appreciated!

Hi Guys,

I have to admit, the Swagger project is one of the most confusing library. I finally managed to get this working with springfox-boot-starter 3.0.0

My config:

gradle: ` plugins { id ‘org.springframework.boot’ version ‘2.4.2’ id ‘io.spring.dependency-management’ version ‘1.0.10.RELEASE’ id ‘java’ }

group = ‘com.curvecue’ version = ‘0.0.1-SNAPSHOT’ sourceCompatibility = ‘1.8’

configurations { compileOnly { extendsFrom annotationProcessor } }

repositories { mavenCentral() maven { url ‘https://repo.spring.io/milestone’ } }

ext { set(‘springCloudVersion’, “2020.0.1”) }

//configurations { // // exclude Tomcat //// compile.exclude module: ‘spring-boot-starter-tomcat’ //}

dependencies {

implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'

// implementation ‘org.springframework.boot:spring-boot-starter-undertow’ implementation ‘org.springframework.boot:spring-boot-starter-actuator’ implementation ‘org.springframework.boot:spring-boot-starter-data-jpa’ implementation ‘org.springframework.boot:spring-boot-starter-thymeleaf’ implementation ‘org.springframework.boot:spring-boot-starter-webflux’

implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'

implementation 'org.flywaydb:flyway-core:7.5.2'

compile group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'

implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.1'

compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'

}

dependencyManagement { imports { mavenBom “org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}” } }

test { useJUnitPlatform() } `

@Configuration @EnableSwagger2 public class SwaggerConfig extends WebMvcConfigurerAdapter { @Bean public Docket apiDocket() { return new Docket( DocumentationType.SWAGGER_2 ) .select() .apis( RequestHandlerSelectors.any() ) .paths( PathSelectors.any() ) .build(); } }

Sample RestController ` @RestController @RequestMapping( “/stream-api/postgres” ) @RequiredArgsConstructor @Slf4j public class PostgresController {

private final UserRepository userRepository;

@GetMapping( value = "/user", produces = MediaType.APPLICATION_NDJSON_VALUE )
public UserEntity getUser( @RequestParam( required = true ) String id ) {
	log.debug( "Looking up for user with id: {}", id );
	Optional<UserEntity> userEntityOptional = userRepository.findById( id );
	return userEntityOptional.orElse( null );
}

} `

And now most importantly the url: http://localhost:8080/swagger-ui/index.html <-- PLS NOTICE there is no context root specified here. I spent hours pointing to http://localhost:8080/stream-api/postgres/swagger-ui/index.html !

Hope this helps. I didn’t have to make any Spring Security adjustments.

Incredible how a library is too confused! I spent already 3 hours trying to fix my simple project, but nothing yet.

This works: http://localhost:8080/v2/api-docs This does not work: http://localhost:8080/swagger-ui/, http://localhost:8080/stream-api/postgres/swagger-ui/index.html

Something missing?

While using the following dependencies, only http://localhost:8080/v2/api-docs is working not this http://localhost:8080/swagger-ui/

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

However, if you add the below dependency instead of the above one, both are working well

    <dependency>
          <groupId>io.springfox</groupId>
          <artifactId>springfox-boot-starter</artifactId>
          <version>3.0.0</version>
    </dependency>

new url is /swagger-ui/, and the / at end is necessary !!!

new url is /swagger-ui/, and the / at end is necessary !!!

Thank you, finally works for me!!!

currently i am using springfox 3.0.0 with spring-boot 2.7.1 version. below link solutions doesn’t work for me. i spend couples of days on it but no luck. can anyone help me for this its urgent, need to solve it ASAP. (http://springfox.github.io/springfox/docs/current/#migrating-from-existing-2-x-version) below issue i am getting Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Mon Jul 06 21:19:55 AEST 2020 There was an unexpected error (type=Not Found, status=404).

while using swagger-ui urls. http://localhost:8081/api-payroll-ng/docs/swagger-ui http://localhost:8081/api-payroll-ng/docs/swagger-ui/index.html

Have you manage to sort this?

No solution worked for me yet

Thank you . It worked for me by adding the <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency> and with the url http://localhost:8080/swagger-ui/

Please look at @fishjam post. To make it work …/swagger-ui/ NOT .html. That need to be fixed