在sping boot上加载swagger-ui时,我在spec!中没有定义任何操作
以下是代码详细信息:
pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.4.8</version>
</dependency>
On my main file,
@OpenAPIDefinition(
info = @Info(
title = "RESTAPI",
//version = "${app.version}",
description = "svsjsjj ssksj",
contact = @Contact(
name = "bajaj",
url = "https://jhakja.com"
)
)
)
@SpringBootApplication
@EnableSwagger2
@ComponentScan(basePackages = { "io.swagger", "io.swagger.api" , "io.swagger.configuration"})
public class Swagger2SpringBoot extends SpringBootServletInitializer implements CommandLineRunner {
// I have sqlitcode + Date and time code,
public static void main(String[] args) throws Exception {
new SpringApplication(Swagger2SpringBoot.class).run(args);
}
@Bean
public Docket customImplementation(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("io.swagger.api"))
.build();
}
}
我只是试着在我的www.example.com上添加如下内容application.properties:
springdoc.paths-to-exclude=/swagger-resources/** //wanted to exclude swagger-resource
springdoc.packagesToScan=io.swagger.api
springdoc.pathsToMatch=restapi/v2,restapi/v2/*
我有许多控制器与以下形式,因为项目是从swagger.io生成-〉导出为 Spring 项目-〉导入相同的IDE
1.接口:
@Validated
@Api(value = "alert", description = "the alert API")
@RequestMapping(value = "/v2")
public interface AlertApi {
@ApiOperation(value = "Finds all alerts", nickname = "findAllAlerts", notes = "Provides list of all alerts", responseContainer = "List", authorizations = {
@Authorization(value = "api_key"),
@Authorization(value = "settings_auth", scopes = {
@AuthorizationScope(scope = "write:settings", description = "modify settings in your system"),
@AuthorizationScope(scope = "read:settings", description = "read your settings")
})
}, tags={ "alert", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", responseContainer = "List"),
@ApiResponse(code = 400, message = "Invalid status value") })
@RequestMapping(value = "/alert/history",
produces = {"application/json" },
method = RequestMethod.GET)
ResponseEntity<Object> findAllAlerts();
}
1.类文件:
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2021-10-12T11:46:11.648Z")
@Controller
public class AlertApiController implements AlertApi {
public ResponseEntity<Object> findAllAlerts() {
// processing
}
}
我也试过创建一个类文件,而不是先创建接口,然后创建类,但没有成功。
@Tag(name = "PingController", description = "This is responsible for give the status of application")
@RestController
@RequestMapping(restapi/v2)
public class PingController {
@Operation(summary = "End-point to test ping")
@GetMapping("/v2/ping")
public ResponseEntity<String> getMessages() {
//other code
}
}
我也有与jwt相关的代码,但移到了不同的包中。
无法加载控制器。需要帮助。
swagger ui displayed
提前感谢!
1条答案
按热度按时间1mrurvl11#
问题似乎出在application.properties中的
springdoc.pathsToMatch
属性值上。试着在www.example.com中注解掉
springdoc.pathsToMatch=restapi/v2,restapi/v2/*
application.properties,看看是否可以解决问题。如果可以,则将值调整为类似springdoc.pathsToMatch=restapi/v2/**
的值。