springboot集成swagger-bootstrap-ui

 

1、官网地址

swagger-bootstrap-ui官网:https://doc.xiaominfo.com/

 

2、导入pom依赖


<dependency>
    <groupId>io.springfoxgroupId>
    <artifactId>springfox-swagger2artifactId>
    <version>2.9.2version>
dependency>
<dependency>
    <groupId>com.github.xiaoymingroupId>
    <artifactId>swagger-bootstrap-uiartifactId>
    <version>1.9.2version>
dependency>

 

3、创建配置文件

项目中创建一个目录,创建配置文件

springboot集成swagger-bootstrap-ui_第1张图片

 

 

3.1、swaggerConfig

package com.xiaomin.config;

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.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
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 customDocket() {
       
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
    }
 
/*  @Bean
    public Docket customDocket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("
学生管理")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xiaomin.controller"))
                .paths(PathSelectors.any())
                .build();
    }*/
    /**
     * name:开发者姓名
     * url:开发者网址
     * email:开发者邮箱
     * @return
    
*/
   
private ApiInfo apiInfo() {
        Contact contact =
new Contact("王晓敏", "http://www.xiaomin2019.xyz", "[email protected]");
       
return new ApiInfoBuilder()
                .title(
"王晓敏测试API接口")//标题
               
.description("API接口的描述")//文档接口的描述
               
.contact(contact)
                .version(
"1.1.0")//版本号
               
.build();
    }
}

 

 

 

 

3.2、WebMvcConfig

package com.xiaomin.config;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.spring.web.SpringfoxWebMvcConfiguration;

@SpringBootApplication
@ConditionalOnClass
(SpringfoxWebMvcConfiguration.class)
public class WebMvcConfig  implements WebMvcConfigurer {

  
@Override
  
public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry.addResourceHandler(
"doc.html").addResourceLocations("classpath:/META-INF/resources/");
      registry.addResourceHandler(
"/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
   }
}

 

 

4、访问

http://localhost:8080/doc.html

截图:

springboot集成swagger-bootstrap-ui_第2张图片

你可能感兴趣的:(springboot)