Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to integrate Swagger in Spring MVC

Shulou Source: shulou.com Published: 2022-06-02 05:31:25 11月17日 Update

This article introduces how to integrate Swagger in Spring MVC. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Swagger integration of SpringMVC component configuration (custom style adjustment) (springmvc-swagger)-integration of swagger static resources and SpringMVC projects-support for custom style development-development environment based on swagger2.2.10 version-tomcat 7.0.78-jdk 1.7 configuration-spring 4.3.13.RELEASESwaggerConfig configuration class 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 initialization configuration file * @ 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 ()) .origindePatterns (". *?") } private ApiInfo apiInfo () {ApiInfo apiInfo = new ApiInfo ("Scooper Activiti REST-API", "Workflow background Interface Test", "My Apps API terms of service", "xiazhaoyang@live.com", "web app", "My Apps API License URL"); return apiInfo }} spring-mvc.xmlspring-servlet.xml web.xml springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:/config/spring/spring-servlet.xml 1 springmvc / index.html/* add style * / .hide {display:none;} / * adjust path * / url = "/ scooper-activiti/api-docs" / * hide headers * / maven depends on 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

Project directory structure

REFRENCE1, swagger integrate https://www.cnblogs.com/jtlgb/p/6734177.htmlhttps://www.2cto.com/kf/201604/499072.htmlhttp://blog.csdn.net/hayre/article/details/51027201http://www.mamicode.com/info-detail-525592.html2, Can't read swagger JSON from http... http://blog.csdn.net/shecanwin/article/details/55667102http://blog.csdn.net/xyw591238/article/details/519391113, No qualifying bean of type 'com.mangofactory.swagger.configuration.SpringSwaggerConfig' available:... https://www.cnblogs.com/driftsky/p/4952918.html4, swagger file upload http://blog.csdn.net/qq_23167527/article/details/78559096swagger static resource file download 1, version download list https://github.com/Yiyuery/swagger-ui2, 2.2.10 download link https://github.com/swagger-api/swagger-ui/tree/v2.2.10

Note: select version 2.0 + for swagger [2.2.10]

Effect.

On how to integrate Swagger in Spring MVC to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Integration version file style development configuration content more resources static project help adjustment good interest writing background head boy buddy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft OPPO Reno Redmi Apple