xml 配置的spring+springMVC 中增加swagger

从尝试着在ssm项目中配置swagger的过程中,疯狂百度、谷歌,仍然配置的有问题,好尴尬。


xml 配置的spring+springMVC 中增加swagger_第1张图片
配置到最后的结果,还不知道怎么用。。。
  1. 趁着热乎着,赶紧把配置的过程先记录一下,再进行下一步配置和试验:
    pom.xml
        
        
            com.mangofactory
            swagger-springmvc
            1.0.2
        
        
          com.fasterxml.jackson.core
          jackson-core
          2.5.1
          
          
          com.fasterxml.jackson.core
          jackson-databind
          2.5.1
          
          
          com.fasterxml.jackson.core
          jackson-annotations
          2.5.1
          

web.xml

   
    
        SpringMVC
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:system/spring-mvc.xml
        
        1
        true
    
    
        SpringMVC
         *.do
    
    
    
        SpringMVC
        /api-docs
    

SwaggerConfig.java

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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableSwagger
@Configuration
public class SwaggerConfig {


    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(".*?");
    }

    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfo(
                "ssm API 测试",
                "API测试",
                "My Apps API terms of service",
                "[email protected]",
                "web app",
                "My Apps API License URL");
        return apiInfo;
    }
}

spring-mvc.xml

    
    

    
    

这块:这个是swagger-ui;复制dist文件夹下面的东西拷贝到项目中
https://github.com/swagger-api/swagger-ui.git

修改:index.html里面的


xml 配置的spring+springMVC 中增加swagger_第2张图片
index.html

换成自己的项目路径+/api-docs

总是出现:

  1. Failed to load spec. 这个错误,处理方法:把swagger-ui的3.*版本换成


    image.png

    v2.0.24版本就变成错误2 了;


    image.png
  1. Can’t read swagger JSON from。。。。。
    在web.xml中添加红框中的,就成了开文那张图了,算是把几个controller显示出来了。。。


    xml 配置的spring+springMVC 中增加swagger_第3张图片
    image.png

你可能感兴趣的:(xml 配置的spring+springMVC 中增加swagger)