I’m trying to run swagger ui on spring boot v 3.2.1 but I’m unable to view on the web ui – http://localhost:8080/webjars/swagger-ui/index.html#/
This is my build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.1'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'com.naman.jain'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
// Disables the default jar task, preventing the creation of a JAR file during the build process.
// This is useful in scenarios where the project does not require a JAR file,
// such as when only a WAR file is needed or in specific modules of a multi-module project.
jar {
enabled = false
}
dependencies {
implementation project(':api')
implementation project(':util')
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
// https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webflux-ui
// implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webflux-ui', version: '2.6.0'
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.5.0'
// To avoid the following error message on Apple silicon (for details, see https://github.com/netty/netty/issues/11693):
// Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider, fallback to system defaults. This may result in incorrect DNS resolutions on MacOS.
implementation group: 'io.netty', name: 'netty-resolver-dns-native-macos', classifier: 'osx-aarch_64'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
tasks.named('test') {
useJUnitPlatform()
}
The logs from the service container:
product-composite-1 |
product-composite-1 | . ____ _ __ _ _
product-composite-1 | /\ / ___'_ __ _ _(_)_ __ __ _
product-composite-1 | ( ( )___ | '_ | '_| | '_ / _` |
product-composite-1 | \/ ___)| |_)| | | | | || (_| | ) ) ) )
product-composite-1 | ' |____| .__|_| |_|_| |___, | / / / /
product-composite-1 | =========|_|==============|___/=/_/_/_/
product-composite-1 | :: Spring Boot :: (v3.2.1)
product-composite-1 |
product-composite-1 | 2024-09-03T21:23:55.107Z INFO 1 --- [ main] j.c.p.ProductCompositeServiceApplication : Starting ProductCompositeServiceApplication v0.0.1-SNAPSHOT using Java 17.0.12 with PID 1 (/application/BOOT-INF/classes started by root in /application)
product-composite-1 | 2024-09-03T21:23:55.124Z DEBUG 1 --- [ main] j.c.p.ProductCompositeServiceApplication : Running with Spring Boot v3.2.1, Spring v6.1.2
product-composite-1 | 2024-09-03T21:23:55.126Z INFO 1 --- [ main] j.c.p.ProductCompositeServiceApplication : The following 1 profile is active: "docker"
product-composite-1 | 2024-09-03T21:24:01.708Z INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
product-composite-1 | 2024-09-03T21:24:01.806Z INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
product-composite-1 | 2024-09-03T21:24:01.807Z INFO 1 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.17]
product-composite-1 | 2024-09-03T21:24:02.169Z INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
product-composite-1 | 2024-09-03T21:24:02.185Z INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 6451 ms
product-composite-1 | 2024-09-03T21:24:06.165Z INFO 1 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator'
product-composite-1 | 2024-09-03T21:24:06.647Z INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path ''
product-composite-1 | 2024-09-03T21:24:06.705Z INFO 1 --- [ main] j.c.p.ProductCompositeServiceApplication : Started ProductCompositeServiceApplication in 13.851 seconds (process running for 15.837)
On trying to open the swagger page, I’m facing the resource not found error on webpage with no logs on docker.
(No static resource swagger-ui/index.html.)
Update 1: Not working with following config as well
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
}
group = 'com.naman.jain'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
// Disables the default jar task, preventing the creation of a JAR file during the build process.
// This is useful in scenarios where the project does not require a JAR file,
// such as when only a WAR file is needed or in specific modules of a multi-module project.
jar {
enabled = false
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
// https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webflux-ui
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.6.0'
implementation project(':api')
implementation project(':util')
// To avoid the following error message on Apple silicon (for details, see https://github.com/netty/netty/issues/11693):
// Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider, fallback to system defaults. This may result in incorrect DNS resolutions on MacOS.
implementation group: 'io.netty', name: 'netty-resolver-dns-native-macos', classifier: 'osx-aarch_64'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
tasks.named('test') {
useJUnitPlatform()
}
3
This is an example from the book. I had the same error)
You should change versions.
In the “api” module, I have:
implementation 'org.springdoc:springdoc-openapi-starter-common:2.6.0'
And in this module:
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.6.0'
PS: I also changed the Spring Boot version to 3.3.3. It works for me.
2
Agree with @kozlovskiy-kirill, you can either bump both spring-boot + springdoc to latest 3.3.x & 2.6.0 OR bump to 3.2.4 that matches springdoc 2.5.0.
See https://github.com/springdoc/springdoc-openapi/releases for info on what version each springdoc release is set up for.
2