I am on Spring boot 3.1.0
and Spring doc 2.1.0
.
Previously I was using springfox and I was forced to migrate to springdoc since springfox didn't support springboot 3.
I followed migration guide this migration guide and here's how my setup looks like.
pom.xml
<!--Swagger dependency-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
Controller
@RestController
@Slf4j
public class HelloController {
@RequestMapping(method = RequestMethod.GET, value = "hi")
public String hi(HttpServletRequest httpRequest) {
return "hi";
}
}
application.properties
#Swagger properties
server.contextPath=/ctx-path
springdoc.packagesToScan=abc.def.ghi
springdoc.paths-to-match=/hi,hi,/ctx-path/hi
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.config-url=/ctx-path/api-docs/swagger-config
springdoc.swagger-ui.disable-swagger-default-url=true
Config bean
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI springShopOpenAPI() {
return new OpenAPI()
.info(new Info().title("service-API")
.description("service API for UI")
.version("Version 1"))
.externalDocs(new ExternalDocumentation()
.description("SpringShop Wiki Documentation")
.url("https://springshop.wiki.github.org/docs"));
}
}
I have tried all the solutions on the internet such as setting appropriate config-url, Having @RestController, and @RequestMapping with method explicitly defined.
But I only see No API definition provided despite all the efforts.