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. 葡萄城首席架构师:前端开发与Web表格控件技术解读

    讲师:Issam Elbaytam,葡萄城集团全球首席架构师(Chief Software Architect of GrapeCity Global).曾任 Data Dynamics.Inc 创始 ...

  2. ibox 的使用

    <div class="ibox float-e-margins"> <div class="ibox-title"> <h5&g ...

  3. Laravel三种中间件的作用

    $middleware 属性: 这个属性称为全局中间件,为什么说是全局中间件呢?因为你的每一次请求,这里面的每个中间件都会执行. $routeMiddleware 属性: 这个属性称为路由中间件,为什 ...

  4. Python基础『一』

    内置数据类型 数据名称 例子 数字: Bool,Complex,Float,Integer True/False; z=a+bj; 1.23; 123 字符串: String '123456' 元组: ...

  5. python 基础(十七)--hashlib加密模块

    hashlib加密模块 两种方式使用 字符串是中文时需要先编码成utf-8 常用加密算法:md5,sha1(已被破解)等... >>> a= hashlib.md5() >&g ...

  6. python基础(十三)--os和sys模块

    os模块 os.getpwd():获取当前工作目录(windows下没有) os.listdir(path):列出目录下的文件 os.remove(path):删出文件 (不能是目录,即文件夹) os ...

  7. vc++6.0中查看函数栈的结构

    栈:一种后进先出的数据结构   比如:弹夹 函数调用的约定 传参顺序 传参媒介 如何传递返回值 平衡参数(堆栈平衡):有且只有被调方(callee)和调用方(caller)一方执行 _cdell (c ...

  8. mydumper,myloader原理及实战

    mydumper 特性 (1)多线程备份(和mysqlpump的多线程不同,mysqlpump多线程备份的粒度是表,mydumper多线程备份的粒度是行,这对于备份大表特别有用)(2)因为是多线程逻辑 ...

  9. Mysql数据库的优化(本文摘自于网络,文章末端有原文链接)

    对于一个以数据为中心的应用,数据库的好坏直接影响到程序的性能,因此数据库性能至关重要.一 般来说,要保证数据库的效率,要做好以下四个方面的工作: ① 数据库设计 ② sql语句优化 ③ 数据库参数配置 ...

  10. MySQL SQL Training

    源于知乎:50道SQL练习题 一.表数据 1.学生表——Student ),Sname ),Sage )); ' , '赵雷' , '1990-01-01' , '男'); ' , '钱电' , '1 ...