<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ### 27.1.5 靜態內容 默認情況下,Spring Boot從classpath下的`/static`(`/public`,`/resources`或`/META-INF/resources`)文件夾,或從`ServletContext`根目錄提供靜態內容。這是通過Spring MVC的`ResourceHttpRequestHandler`實現的,你可以自定義`WebMvcConfigurerAdapter`并覆寫`addResourceHandlers`方法來改變該行為(加載靜態文件)。 在單機web應用中,容器會啟動默認的servlet,并用它加載`ServletContext`根目錄下的內容以響應那些Spring不處理的請求。大多數情況下這都不會發生(除非你修改默認的MVC配置),因為Spring總能夠通過`DispatcherServlet`處理這些請求。 你可以設置`spring.resources.staticLocations`屬性自定義靜態資源的位置(配置一系列目錄位置代替默認的值),如果你這樣做,默認的歡迎頁面將從自定義位置加載,所以只要這些路徑中的任何地方有一個`index.html`,它都會成為應用的主頁。 此外,除了上述標準的靜態資源位置,有個例外情況是[Webjars內容](http://www.webjars.org/)。任何在`/webjars/**`路徑下的資源都將從jar文件中提供,只要它們以Webjars的格式打包。 **注** 如果你的應用將被打包成jar,那就不要使用`src/main/webapp`文件夾。盡管該文件夾是通常的標準格式,但它僅在打包成war的情況下起作用,在打包成jar時,多數構建工具都會默認忽略它。 Spring Boot也支持Spring MVC提供的高級資源處理特性,可用于清除緩存的靜態資源或對WebJar使用版本無感知的URLs。 如果想使用針對WebJars版本無感知的URLs(version agnostic),只需要添加`webjars-locator`依賴,然后聲明你的Webjar。以jQuery為例,`"/webjars/jquery/dist/jquery.min.js"`實際為`"/webjars/jquery/x.y.z/dist/jquery.min.js"`,`x.y.z`為Webjar的版本。 **注** 如果使用JBoss,你需要聲明`webjars-locator-jboss-vfs`依賴而不是`webjars-locator`,否則所有的Webjars將解析為`404`。 以下的配置為所有的靜態資源提供一種緩存清除(cache busting)方案,實際上是將內容hash添加到URLs中,比如`<link href="/css/spring-2a2d595e6ed9a0b24f027f2b63b134d6.css"/>`: ```properties spring.resources.chain.strategy.content.enabled=true spring.resources.chain.strategy.content.paths=/** ``` **注** 實現該功能的是`ResourceUrlEncodingFilter`,它在模板運行期會重寫資源鏈接,Thymeleaf,Velocity和FreeMarker會自動配置該filter,JSP需要手動配置。其他模板引擎還沒自動支持,不過你可以使用[ResourceUrlProvider](http://docs.spring.io/spring/docs/4.3.3.RELEASE/javadoc-api/org/springframework/web/servlet/resource/ResourceUrlProvider.html)自定義模塊宏或幫助類。 當使用比如JavaScript模塊加載器動態加載資源時,重命名文件是不行的,這也是提供其他策略并能結合使用的原因。下面是一個"fixed"策略,在URL中添加一個靜態version字符串而不需要改變文件名: ```properties spring.resources.chain.strategy.content.enabled=true spring.resources.chain.strategy.content.paths=/** spring.resources.chain.strategy.fixed.enabled=true spring.resources.chain.strategy.fixed.paths=/js/lib/ spring.resources.chain.strategy.fixed.version=v12 ``` 使用以上策略,JavaScript模塊加載器加載`"/js/lib/"`下的文件時會使用一個固定的版本策略`"/v12/js/lib/mymodule.js"`,其他資源仍舊使用內容hash的方式`<link href="/css/spring-2a2d595e6ed9a0b24f027f2b63b134d6.css"/>`。查看[ResourceProperties](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java)獲取更多支持的選項。 **注** 該特性在一個專門的[博文](https://spring.io/blog/2014/07/24/spring-framework-4-1-handling-static-web-resources)和Spring框架[參考文檔](https://spring.io/blog/2014/07/24/spring-framework-4-1-handling-static-web-resources)中有透徹描述。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看