SpringBoot整合SwaggerUi启动时出现错误该如何解决?
- 内容介绍
- 文章标签
- 相关推荐
本文共计376个文字,预计阅读时间需要2分钟。
SwaggerUi是一个自动生成接口文档的工具,同时支持测试这些接口的功能。在SpringBoot项目中集成SwaggerUi,需要引入以下依赖和配置:
propertiesswagger.version=2.6.1
xml org.springframework.boot spring-boot-starter-swagger ${swagger.version}
SwaggerUi是一个自动生成接口文档,并且还可以去测试这些接口的东西。
SpringBoot集成SwaggerUi
引入依赖
<properties> <swagger.version>2.6.1</swagger.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${swagger.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger.version}</version> </dependency> </dependencies>
编写Swagger配置类com.wjh.config.SwaggerConfig
package com.wjh.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration //表示是Swagger的配置类 @EnableSwagger2 //启用Swagger2 public class SwaggerConfig { @Bean public Docket api(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .pathMapping("/") .select() .paths(PathSelectors.regex("/.*")) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder().title("我的接口文档") .contact(new Contact("wjh", "", "wjh_dan@163.com")) .description("这是swaggerUI生成的接口文档") .version("1.0.0.0") .build(); } }
编写接口方法类com.wjh.server.MyMethod
package com.wjh.server; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.servlet.localhost/swagger-ui.html
到此这篇关于SpringBoot集成SwaggerUi以及启动时遇到的错误的文章就介绍到这了,更多相关SpringBoot集成Swagger内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!
本文共计376个文字,预计阅读时间需要2分钟。
SwaggerUi是一个自动生成接口文档的工具,同时支持测试这些接口的功能。在SpringBoot项目中集成SwaggerUi,需要引入以下依赖和配置:
propertiesswagger.version=2.6.1
xml org.springframework.boot spring-boot-starter-swagger ${swagger.version}
SwaggerUi是一个自动生成接口文档,并且还可以去测试这些接口的东西。
SpringBoot集成SwaggerUi
引入依赖
<properties> <swagger.version>2.6.1</swagger.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${swagger.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger.version}</version> </dependency> </dependencies>
编写Swagger配置类com.wjh.config.SwaggerConfig
package com.wjh.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration //表示是Swagger的配置类 @EnableSwagger2 //启用Swagger2 public class SwaggerConfig { @Bean public Docket api(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .pathMapping("/") .select() .paths(PathSelectors.regex("/.*")) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder().title("我的接口文档") .contact(new Contact("wjh", "", "wjh_dan@163.com")) .description("这是swaggerUI生成的接口文档") .version("1.0.0.0") .build(); } }
编写接口方法类com.wjh.server.MyMethod
package com.wjh.server; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.servlet.localhost/swagger-ui.html
到此这篇关于SpringBoot集成SwaggerUi以及启动时遇到的错误的文章就介绍到这了,更多相关SpringBoot集成Swagger内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

