引用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只需引入三个即可
- <!-- swagger -->
- <dependency>
- <groupId>com.mangofactory</groupId>
- <artifactId>swagger-springmvc</artifactId>
- <version>1.0.2</version>
- </dependency>
- <dependency>
- <groupId>com.mangofactory</groupId>
- <artifactId>swagger-models</artifactId>
- <version>1.0.2</version>
- </dependency>
- <dependency>
- <groupId>com.wordnik</groupId>
- <artifactId>swagger-annotations</artifactId>
- <version>1.3.11</version>
- </dependency>
3.配置swaggerConfig.class 存放在com.thinkgem.jeesite.common.web下
@ComponentScan(basePackages ={"com.thinkgem.jeesite.modules.sys.web"})既扫描的路径根据自己的情况写
- package com.thinkgem.jeesite.common.web;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.ComponentScan;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
- import org.springframework.web.servlet.config.annotation.EnableWebMvc;
- import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
- 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;
- /**
- * @author xiegx
- * @version 创建时间:2016-8-16 下午2:01:10
- * SwaggerUI配置
- */
- @Configuration
- @EnableSwagger
- @EnableWebMvc
- @ComponentScan(basePackages ={"com.thinkgem.jeesite.modules.sys.web"})
- public class SwaggerConfig extends WebMvcConfigurerAdapter {
- 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(".*")
- .swaggerGroup("XmPlatform")
- .apiVersion("1.0.0");
- }
- @Override
- public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
- configurer.enable();
- }
- /*
- * "标题 title",
- * "描述 description",
- * "termsOfServiceUrl",
- * "联系邮箱 contact email",
- * "许可证的类型 license type",
- * "许可证的链接 license url"
- */
- private ApiInfo apiInfo()
- {
- ApiInfo apiInfo = new ApiInfo(
- "Jeesite平台API文档",
- "后台RESTful API",
- "",//
- "admin@xmplatform.com",
- "",
- "");
- return apiInfo;
- }
- }
4.配置spring-mvc.xml
- <context:component-scan base-package="com.thinkgem.jeesite.modules.sys.web" use-default-filters="false">
- <context:include-filter type="annotation" expression="org.springframework.context.annotation.Configuration"/>
- </context:component-scan>
5.修改index.html
ip:端口号要根据自己需要的服务器对应的地址修改
6.启动工程
http://127.0.0.1:8080/jeesite/static/swagger/dist/index.html