升级到 spring 3 时出现 Swagger 问题

问题描述 投票:0回答:0

我正在将我的项目从 spring/java 8 升级到 spring 3/java 17。应用程序已启动并正在运行,但是当我检查 swagger 页面时,它没有显示 API。相反,它只是说“规范中没有定义任何操作!” 这是大摇大摆的规格:

{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers":[{"url":"http://localhost:8080/aais-pricing-promotions","description":"Generated server url"}],"paths":{},"components":{}}

我更新了依赖项,所以这是我的 pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.3</version>
        <relativePath/>
....
        <java.version>17</java.version>
....
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
...

我的控制器方法的一部分:

    @PostMapping("/v1/promotions")
    @Operation(summary = "Get Promotion details based on request body", tags = {Constants.APP_NAME_CONSTANT},
            responses = {@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = Constants.SERVICE_AAIS_200),
                    @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "204", description = Constants.SERVICE_AAIS_204),
                    @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = Constants.SERVICE_AAIS_400)})
    public ResponseEntity<PromotionsDTO> getPromotions(
            @Parameter(name = "requestBody", description = "requestBody") @Valid
            @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = @Content(
                    examples = { @ExampleObject(name = "promotionsRequestBody", value = Constants.PROMOTIONS_REQUEST_EXAMPLE) })) @RequestBody PromotionsRequestBody requestBody)
    {
        PromotionsDTO response;
...

当我尝试从 postman 访问端点时,它返回 404 Not Found,所以配置似乎有问题?我不确定从哪里开始,因为 spring 应用程序中没有日志或异常发生,任何建议将不胜感激!

java spring spring-boot swagger-ui springdoc
© www.soinside.com 2019 - 2024. All rights reserved.