springboot 简单的整合 swagger

tech2023-10-24  93

下面是swagger的官网 https://swagger.io/

1 配置pom io.springfox springfox-swagger2 s p r i n g f o x − v e r s i o n < / v e r s i o n > < / d e p e n d e n c y > < d e p e n d e n c y > < g r o u p I d > i o . s p r i n g f o x < / g r o u p I d > < a r t i f a c t I d > s p r i n g f o x − s w a g g e r − u i < / a r t i f a c t I d > < v e r s i o n > {springfox-version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version> springfoxversion</version></dependency><dependency><groupId>io.springfox</groupId><artifactId>springfoxswaggerui</artifactId><version>{springfox-version} 配置版本 2.7.0

2 配置yml/application #swagger springfox.documentation.swagger.v2.path=/docs

3 启动swagger

4 编写config类 @javax.annotation.Generated(value = “io.swagger.codegen.languages.SpringCodegen”, date = “2020-09-02T09:51:51.983Z”)

@Configuration public class SwaggerDocumentationConfig {

ApiInfo apiInfo() { return new ApiInfoBuilder().title("测试用的标题") .description( "这是个测试类") .license("Apache 2.0").licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") .termsOfServiceUrl("http://www.apache.org/licenses/LICENSE-2.0.html").version("1.0.1").contact(new Contact("a", "b", "apiteam@swagger.io")).build(); } @Bean public Docket customImplementation() { return new Docket(DocumentationType.SWAGGER_2).select() .apis(RequestHandlerSelectors.basePackage("com.xj")).build() /*.directModelSubstitute(org.threeten.bp.LocalDate.class, java.sql.Date.class) .directModelSubstitute(org.threeten.bp.OffsetDateTime.class, java.util.Date.class)*/ .apiInfo(apiInfo()); }

}

启动后访问: http://localhost:8080/swagger-ui.html

看到下面的页面,启动就成功了

最新回复(0)