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
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
//springboot 集成swagger2.2后静态资源404,添加如下两行配置
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/"); registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
super.addResourceHandlers(registry);
} @Bean
public Docket docket() {
//最重要的就是这里,定义了/test/.*开头的rest接口都分在了test分组里,可以通过/v2/api-docs?group=test得到定义的json
StopWatch watch = new StopWatch();
watch.start();
Docket docket = new Docket(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("xx0@qq.com", null, null))
.license("Apache 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.version("1.0.0")
.build();
} }

  

springboot 集成swagger2.x 后静态资源报404的更多相关文章

  1. springboot集成swagger2报Illegal DefaultValue null for parameter type integer

    springboot集成swagger2,实体类中有int类型,会报" Illegal DefaultValue null for parameter type integer"的 ...

  2. springboot打包后静态资源webapp文件夹无法打包进去

    1.如下图的目录结构 webapp 文件夹和resources 文件夹同级.使用mvn clean install 打包过后项目启动访问,静态资源页面404. 2.原因,springboot 打包时候 ...

  3. SpringBoot集成Swagger2实现Restful(类型转换错误解决办法)

    1.pom.xml增加依赖包 <dependency> <groupId>io.springfox</groupId> <artifactId>spri ...

  4. springboot集成swagger2构建RESTful API文档

    在开发过程中,有时候我们需要不停的测试接口,自测,或者交由测试测试接口,我们需要构建一个文档,都是单独写,太麻烦了,现在使用springboot集成swagger2来构建RESTful API文档,可 ...

  5. IntelliJ IDEA+SpringBoot中静态资源访问路径陷阱:静态资源访问404

    IntelliJ IDEA+SpringBoot中静态资源访问路径陷阱:静态资源访问404 .embody{ padding:10px 10px 10px; margin:0 -20px; borde ...

  6. SpringBoot集成Swagger2在线文档

    目录 SpringBoot集成Swagger2在线文档 前言 集成SpringBoot 登录接口文档示例 代码 效果 注解说明 总结 SpringBoot集成Swagger2在线文档 前言 不得不说, ...

  7. SpringBoot第四集:静态资源与首页定(2020最新最易懂)

    SpringBoot第四集:静态资源与首页定(2020最新最易懂) 问题 SpringBoot构建的项目结构如下:没有webapp目录,没有WEB-INF等目录,那么如果开发web项目,项目资源放在那 ...

  8. springboot 2.X 在访问静态资源的的时候出现404的问题

    通过idea快速搭建一个springboot项目: springboot版本2.1.6 在网上看的资料,springboot静态资源访问如下: "classpath:/META‐INF/re ...

  9. SpringBoot集成Swagger2并配置多个包路径扫描

    1. 简介   随着现在主流的前后端分离模式开发越来越成熟,接口文档的编写和规范是一件非常重要的事.简单的项目来说,对应的controller在一个包路径下,因此在Swagger配置参数时只需要配置一 ...

随机推荐

  1. HashMap集合-遍历方法

    # HashMap集合-遍历方法 先定义好集合: public static void main(String[] args) { Map<String,String> onemap=ne ...

  2. docker login Harbor时报错403 Forbidden

    背景 在本地搭建了harbor后,在进行了相关配置后,还是报错:Error response from daemon: login attempt to http://10.xx.xx.xx:8000 ...

  3. python学习-7 条件语句 while循环 + 练习题

    1.死循环 while 1 == 1: print('ok') 结果是一直循环 2.循环 count = 0 while count < 10: print(count) count = cou ...

  4. django 中静态文件项目加载问题

    问题描述: django项目中创建了多个app后,每个app中都有对应的static静态文件.整个项目运行时这些静态文件的加载就是一个问题,因为整个项目我只参与了一部分,项目部署之类的并没有参与.我写 ...

  5. 1、ECharts(中国地图篇)的使用

    一.网址:            http://echarts.baidu.com/download.html点击:            完整下载文件:        echarts.min.js ...

  6. Windows编程 Windows程序的生与死(中)

    <pre style=""><pre class="cpp" name="code">1 #include < ...

  7. java Map 四种遍历方法

    public static void main(String[] args) { Map<String, String> map = new HashMap<String, Stri ...

  8. JavaScript获取数组索引

    JavaScript获取数组索引: <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...

  9. java中的多态总结

    一.多态的概述 ava作为面向对象的语言,同样可以描述一个事物的多种形态.如Student类继承了Person类,一个Student的对象便既是Student,又是Person. Java中多态的代码 ...

  10. InnoDB意向锁的作用

    https://www.zhihu.com/question/51513268?sort=created IX,IS是表级锁,不会和行级的X,S锁发生冲突.只会和表级的X,S发生冲突. 意向锁是一种快 ...