springboot after integration swagger2.x static resource report 404

package com.bgs360.configuration;

import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.StopWatch;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import springfox.documentation.builders.ApiInfoBuilder;
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;

import static springfox.documentation.builders.PathSelectors.regex;

/**
 * <pre>
 * Swagger配置类
 * </pre>
 *
 * @author zyg
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurationSupport implements EnvironmentAware {
  private Environment environment;

  @Override
  public void setEnvironment(Environment environment) {
    this.environment = environment;
  }

  @Override
  void addResourceHandlers public (ResourceHandlerRegistry Registry) {
    watch.start();
    registry.addResourceHandler ( "The ui.html-Swagger") 
        .addResourceLocations ( "CLASSPATH: / the META-INF / Resources /"); the // springboot integrated swagger2.2 static resources 404, add the following two lines arranged 
    registry.addResourceHandler ( " / ** ") 
    .addResourceLocations (" CLASSPATH: / static / "); 
    registry.addResourceHandler (" / webjars / ** ") 
        .addResourceLocations (" CLASSPATH: / the META-INF / Resources / webjars / "); 
    super.addResourceHandlers (Registry); 
  } 
  @Bean 
  public Docket Docket No. () { 
    // is the most important here, defines the rest of the interfaces are beginning /test/.* points in the test packet, can / v2 / api-docs group? = test defined obtained JSON 
    the StopWatch Watch the StopWatch new new = (); 
    Docket No. Docket No. Docket new new = (DocumentationType.SWAGGER_2)
        .groupName("org")
    


        .apiInfo(this.apiInfo())
        .select()
        .apis(RequestHandlerSelectors.any())
        .paths(regex("/org/building/.*"))
        .build();
    watch.stop();
    return docket;
  }

  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
        .title("测试Api")
        .description("测试Api接口信息")
        .contact(new Contact("[email protected]", null, null))
        .license("Apache 2.0")
        .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
        .version("1.0.0")
        .build();
  }

}

  

Guess you like

Origin www.cnblogs.com/irobotzz/p/12000668.html
Recommended