zoukankan      html  css  js  c++  java
  • spring boot配置文件中 spring.mvc.static-path-pattern 配置项

    spring boot项目中的静态资源文件存放在static文件下面,当通过浏览器访问这些静态文件时,发现必须要添加static作为前缀才能访问,折腾了一番后发现,这个前缀跟 spring.mvc.static-path-pattern 这个配置项有关。

    spring:
        mvc:
            static-path-pattern: /static/**

    项目中application.yml配置文件中,存在如上配置项时,访问静态资源文件要加static才行,当把这个配置项除掉时,不用加static作为前缀亦可进行正常访问。

    当spring boot自动装配 org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration,当执行到org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#addResourceHandlers方法时,类org.springframework.boot.autoconfigure.web.WebMvcProperties#staticPathPattern的默认值为 "/**"。如果配置项文件中存在spring.mvc.static-path-pattern 配置项,默认的配置项将会被覆盖。

    当通过浏览器进行访问时,springMVC使用SimpleUrlHandlerMapping进行路由映射,当执行到方法 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping#lookupHandler 时,将会使用 spring.mvc.static-path-pattern 配置项来匹配url

  • 相关阅读:
    rabbitMq(2)之“Work”模式
    rabbitmq(1)之"Hello World"模式
    Maven的实用基础命令
    RabbitMq(3)之“发布/订阅”模式
    mac rabbitmq安装以及入门
    Mac 安装Homebrew
    多线程通讯之管道
    CentOS中防火墙之iptables
    CentOS中防火墙之Firewall
    Redis的简介
  • 原文地址:https://www.cnblogs.com/yql1986/p/9219137.html
Copyright © 2011-2022 走看看