eclipse 搭建 swagger-ui(maven项目 springboot框架)

现在越来越流行swagger,现在把原来的Maven的项目加入swagger

其实非常简单 

1 pom.xml    引入两个jar就可以

  
    
	io.springfox
	springfox-swagger2
	2.7.0
    
    
       io.springfox
       springfox-swagger-ui
       2.7.0
    

2 SpringBootApp.java  添加注解 @EnableSwagger2

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableSwagger2
public class App {
	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}
}

3 启动项目 访问 http://localhost:8080/swagger-ui.html

eclipse 搭建 swagger-ui(maven项目 springboot框架)_第1张图片

最基本的swagger就出来了

4 swaggerConfig.java 配置文件(这样页面中出现的东西我们就可以更改了)

SpringBoot的启动ApplicationApp.java同目录下创建java文件 swaggerConfig.java

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.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2
public class swaggerConfig {
	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("controller")
				.apiInfo(apiInfo())
				.select()
				.apis(RequestHandlerSelectors.basePackage("com.pusamm"))//项目包名
				.paths(PathSelectors.any()).build();
	}


	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("移动C2M RESTful API")
				.description("swagger-ui")
				.termsOfServiceUrl("").version("1.0").build();
	}
eclipse 搭建 swagger-ui(maven项目 springboot框架)_第2张图片

页面就编程这样了,其他的根据自己项目需求修改就可以了



你可能感兴趣的:(swagger搭建,swagger-ui,swagger2)