Springfox与SpringMVC集成笔记

1、pom.xml增加依赖


 
io.springfox  
    springfox-swagger2 
    2.4.0 
 
 
    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.4.4 


     com.google.guava  
     guava  
     19.0  


2、写配置类

@EnableSwagger2
public class SwaggerConfig {

@Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .useDefaultResponseMessages(false);
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Api Documents")
                .contact(new Contact(“zhangfengcheng", "", “[email protected]"))
                .build();
    }
}

3、配置servlet-context.xml,加上上面配置类的bean和静态资源访问:




4、配置web.xml,加上:


     appServlet  
     org.springframework.web.servlet.DispatcherServlet
     
     contextConfigLocation
     classpath:servlet-context.xml
     
     1
   

    appServlet
/v2/api-docs

5、下载swagger-ui,解压后把dist目录下的所有文件放到项目路径/src/webapp/apidoc目录下面

6、修改apidoc/index.html:

url = "/v2/api-docs";

7、ok,配置完成,输入http://localhost:8081/apidoc

你可能感兴趣的:(Springfox与SpringMVC集成笔记)