jeesite项目集成swagger

引用https://blog.csdn.net/opopopwqwqwq/article/details/75087748


1.下载swagger UI

https://github.com/swagger-api/swagger-ui/releases

解压 swagger直接放到jeesite项目的jeesite项目名\src\main\webapp\static\下  就可以 例如: 



2.jar引用

jeesite项目pom.xml只需引入三个即可

[html]  view plain  copy
  1. <!-- swagger -->  
  2. <dependency>  
  3.     <groupId>com.mangofactory</groupId>  
  4.     <artifactId>swagger-springmvc</artifactId>  
  5.     <version>1.0.2</version>  
  6. </dependency>  
  7. <dependency>  
  8.     <groupId>com.mangofactory</groupId>  
  9.     <artifactId>swagger-models</artifactId>  
  10.     <version>1.0.2</version>  
  11. </dependency>  
  12. <dependency>  
  13.     <groupId>com.wordnik</groupId>  
  14.     <artifactId>swagger-annotations</artifactId>  
  15.     <version>1.3.11</version>  
  16. </dependency>   

3.配置swaggerConfig.class 存放在com.thinkgem.jeesite.common.web下

@ComponentScan(basePackages ={"com.thinkgem.jeesite.modules.sys.web"})既扫描的路径根据自己的情况写

[java]  view plain  copy
  1. package com.thinkgem.jeesite.common.web;  
  2. import org.springframework.beans.factory.annotation.Autowired;  
  3. import org.springframework.context.annotation.Bean;  
  4. import org.springframework.context.annotation.ComponentScan;  
  5. import org.springframework.context.annotation.Configuration;  
  6. import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;  
  7. import org.springframework.web.servlet.config.annotation.EnableWebMvc;  
  8. import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;  
  9. import com.mangofactory.swagger.configuration.SpringSwaggerConfig;  
  10. import com.mangofactory.swagger.models.dto.ApiInfo;  
  11. import com.mangofactory.swagger.plugin.EnableSwagger;  
  12. import com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin;  
  13.   
  14.   
  15. /** 
  16.  * @author xiegx 
  17.  * @version 创建时间:2016-8-16 下午2:01:10 
  18.  * SwaggerUI配置 
  19.  */  
  20. @Configuration  
  21. @EnableSwagger  
  22. @EnableWebMvc  
  23. @ComponentScan(basePackages ={"com.thinkgem.jeesite.modules.sys.web"})    
  24. public class SwaggerConfig extends WebMvcConfigurerAdapter {    
  25.   
  26.     private SpringSwaggerConfig springSwaggerConfig;  
  27.   
  28.     /** 
  29.      * Required to autowire SpringSwaggerConfig 
  30.      */  
  31.     @Autowired  
  32.     public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig)  
  33.     {  
  34.         this.springSwaggerConfig = springSwaggerConfig;  
  35.     }  
  36.   
  37.     /** 
  38.      * Every SwaggerSpringMvcPlugin bean is picked up by the swagger-mvc 
  39.      * framework - allowing for multiple swagger groups i.e. same code base 
  40.      * multiple swagger resource listings. 
  41.      */  
  42.     @Bean  
  43.     public SwaggerSpringMvcPlugin customImplementation()  
  44.     {  
  45.         return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)  
  46.                 .apiInfo(apiInfo())  
  47.                 .includePatterns(".*")  
  48.                 .swaggerGroup("XmPlatform")  
  49.                 .apiVersion("1.0.0");  
  50.     }  
  51.   
  52.     @Override    
  53.     public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {    
  54.       configurer.enable();    
  55.     }    
  56.     /* 
  57.      * "标题 title", 
  58.      * "描述 description",  
  59.      * "termsOfServiceUrl",  
  60.      * "联系邮箱 contact email", 
  61.      * "许可证的类型 license type",  
  62.      * "许可证的链接 license url" 
  63.      */  
  64.     private ApiInfo apiInfo()  
  65.     {  
  66.         ApiInfo apiInfo = new ApiInfo(  
  67.                 "Jeesite平台API文档",  
  68.                 "后台RESTful API",  
  69.                 "",//  
  70.                 "admin@xmplatform.com",  
  71.                 "",  
  72.                 "");  
  73.         return apiInfo;  
  74.     }  
  75. }  

4.配置spring-mvc.xml

[html]  view plain  copy
  1. <context:component-scan base-package="com.thinkgem.jeesite.modules.sys.web" use-default-filters="false">  
  2.     <context:include-filter type="annotation" expression="org.springframework.context.annotation.Configuration"/>  
  3. </context:component-scan>  

5.修改index.html


ip:端口号要根据自己需要的服务器对应的地址修改

6.启动工程

http://127.0.0.1:8080/jeesite/static/swagger/dist/index.html




  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值