SpringMVC中怎么整合Swagger
这篇文章给大家介绍Spring MVC中怎么整合Swagger,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
创新互联是专业的平坝网站建设公司,平坝接单;提供网站制作、成都网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行平坝网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
Spring MVC 组件配置 之 Swagger整合(自定义样式调整)(springmvc-swagger)
- swagger静态资源和SpringMVC项目整合 - 支持自定义样式开发 - 基于swagger2.2.10版本开发
开发环境
- tomcat 7.0.78 - jdk 1.7+ - spring 4.3.13.RELEASE
SwaggerConfig 配置类
package cn.com.showclear.config; import com.mangofactory.swagger.configuration.SpringSwaggerConfig; import com.mangofactory.swagger.models.dto.ApiInfo; import com.mangofactory.swagger.plugin.EnableSwagger; import com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.servlet.config.annotation.EnableWebMvc; /** * Swagger初始化配置文件 * @author YF-XIACHAOYANG * @date 2017/12/26 10:13 */ @EnableWebMvc @EnableSwagger @ComponentScan(basePackages = "cn.com.showclear.activiti.controller.data") public class SwaggerConfig { private SpringSwaggerConfig springSwaggerConfig; /** * Required to autowire SpringSwaggerConfig */ @Autowired public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) { this.springSwaggerConfig = springSwaggerConfig; } /** * Every SwaggerSpringMvcPlugin bean is picked up by the swagger-mvc * framework - allowing for multiple swagger groups i.e. same code base * multiple swagger resource listings. */ @Bean public SwaggerSpringMvcPlugin customImplementation() { return new SwaggerSpringMvcPlugin(this.springSwaggerConfig) .apiInfo(apiInfo()) .includePatterns(".*?"); } private ApiInfo apiInfo() { ApiInfo apiInfo = new ApiInfo( "Scooper Activiti REST-API", "工作流后台接口测试", "My Apps API terms of service", "xiazhaoyang@live.com", "web app", "My Apps API License URL"); return apiInfo; } }
spring-mvc.xml
spring-servlet.xml
web.xml
springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:/config/spring/spring-servlet.xml 1 springmvc /
index.html
/*添加样式*/ /*调整路径*/ url = "/scooper-activiti/api-docs"; /*隐藏头部*/maven 依赖
com.mangofactory swagger-springmvc 0.9.5 com.fasterxml.jackson.core jackson-annotations 2.4.4 com.fasterxml.jackson.core jackson-databind 2.4.4 com.fasterxml.jackson.core jackson-core 2.8.9 项目目录结构
REFRENCE
1、swagger整合 https://www.cnblogs.com/jtlgb/p/6734177.html https://www.2cto.com/kf/201604/499072.html http://blog.csdn.net/hayre/article/details/51027201 http://www.mamicode.com/info-detail-525592.html 2、Can't read swagger JSON from http... http://blog.csdn.net/shecanwin/article/details/55667102 http://blog.csdn.net/xyw591238/article/details/51939111 3、No qualifying bean of type 'com.mangofactory.swagger.configuration.SpringSwaggerConfig' available: ... https://www.cnblogs.com/driftsky/p/4952918.html 4、swagger文件上传的写法 http://blog.csdn.net/qq_23167527/article/details/78559096swagger静态资源文件下载
1、版本下载列表 https://github.com/Yiyuery/swagger-ui 2、2.2.10下载链接 https://github.com/swagger-api/swagger-ui/tree/v2.2.10注意:swagger 版本选择 2.0+ 版本 [2.2.10]
效果
关于Spring MVC中怎么整合Swagger就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
网站名称:SpringMVC中怎么整合Swagger
网址分享:http://ybzwz.com/article/ghohhh.html