![](/img/trans.png)
[英]JAVA: Parsing OPEN API with swagger.v3.parser.OpenAPI
[英]Can't open OpenApi (Swagger) page
搖籃:
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.13'
implementation group: 'io.swagger.core.v3', name: 'swagger-annotations', version: '2.2.7'
特性:
springdoc.swagger-ui.enabled=true
springdoc.swagger-ui.path=/swagger-ui.html
控制器:
@RestController
@RequestMapping("/api/v1/cheque")
@FieldDefaults(level = AccessLevel.PRIVATE,makeFinal = true)
public class ChequeController {
ProductService productService;
public ChequeController(ProductService productService) {
this.productService = productService;
}
@GetMapping(value = "/get/{id}", produces = "application/json")
public Optional<Product> getByid(@PathVariable Long id) {
return productService.getById(id);
}
@GetMapping("/test")
public String test() {
return "test";
}
}
會議:
@Configuration
public class OpenApiConfiguration {
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(
new Info()
.title("Example Swagger Api")
.version("1.0.0")
);
}
}
嘗試在localhost:8080/swagger-ui.html
中打開並獲取:
Whitelabel Error Page There was an unexpected error (type=Not Found, status=404).
在https://springdoc.org/#getting-started中說,它會自動將 swagger-ui 部署到 spring-boot 應用程序
我做錯了什么
對於 swagger v3+,swagger ui 默認訪問現在是swagger-ui/
而不是swagger-ui.html
您應該可以通過將 url 修改為localhost:8080/swagger-ui/
來訪問
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.