zoukankan      html  css  js  c++  java
  • SpringBoot配置SwaggerUI访问404错误

    先引用一下别的仁兄的地址

    http://blog.csdn.net/hwangfantasy/article/details/66542602   颜艺公社

    上面这位仁兄说的也不够清晰,在这里我补充一下。

    先说明原因,出现404不是说文件没有,而是映射出现了问题,特别是静态文件映射。

    这里亲测成功,废话不多说,直接上代码

     1 package com.co.example.config;
     2 
     3 import org.springframework.context.annotation.Configuration;
     4 import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
     5 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
     6 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
     7 import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
     8 
     9 import com.co.example.base.interceptor.BaseInterceptor;
    10 /**
    11  * 拦截器配置
    12  * @author zyl
    13  *
    14  */
    15 @Configuration
    16 public class ServletContextConfig extends WebMvcConfigurationSupport {
    17 
    18     /**
    19      * 发现如果继承了WebMvcConfigurationSupport,则在yml中配置的相关内容会失效。
    20      * 需要重新指定静态资源
    21      * @param registry
    22      */
    23     @Override
    24     public void addResourceHandlers(ResourceHandlerRegistry registry) {
    25         registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
    26         registry.addResourceHandler("swagger-ui.html")
    27         .addResourceLocations("classpath:/META-INF/resources/");
    28         registry.addResourceHandler("/webjars/**")
    29         .addResourceLocations("classpath:/META-INF/resources/webjars/");
    30         super.addResourceHandlers(registry);
    31     }
    32 
    33 
    34     /**
    35      * 配置servlet处理
    36      */
    37     @Override
    38     public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
    39         configurer.enable();
    40     }
    41 
    42 }

    在本配置文件中加入第26-29行代码,搞定

     

  • 相关阅读:
    Silverlight DataGrid 获取 Row 左键双击事件
    数据结果集拼接到一行
    程序“[6040] iisexpress.exe”已退出,返回值为 0 (0x0)。
    新手用WPF山寨QQ管家7.6(二)
    风向十六方位图和温度湿度图
    新手向使用XAML画出Win8风格图标的照相机,小姐你相机~~
    新手用WPF山寨QQ管家7.6(一)
    实验一
    实验5
    实验4
  • 原文地址:https://www.cnblogs.com/moncat/p/7218061.html
Copyright © 2011-2022 走看看