Spring Boot 无法打开OpenApi(Swagger)页面

14ifxucb  于 2022-12-18  发布在  Spring
关注(0)|答案(1)|浏览(298)

等级:

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 启动的应用程序中
我做错了什么

oprakyz7

oprakyz71#

对于swagger v3+,swagger ui的默认访问权限现在是swagger-ui/而不是swagger-ui.html您应该可以通过将url修改为localhost:8080/swagger-ui/来访问

相关问题