Spring-boot integration Freemarker introduces static resources CSS, JS, etc.

Source: Internet
Author: User

I. Overview

Springboot default static resource access path is:/static or/public or/resources or/meta-inf/resources such addresses must be defined in the Src/main/resources directory file, This can be achieved at the start of the project can be automatically loaded as the project static address directory to classpath, static access to the address is actually using Resourcehttprequesthandler The core processor is loaded into Webmvcconfigureradapter to overwrite the Addresourcehandlers method. The static access to the directory is redefined. We can also implement this method by manually specifying the static access path by inheriting Webmvcconfigureradapter to override the internal method addresourcehandlers can also achieve the effect we want.

Second, static resource allocation scheme

Scenario 1, the default adoption of Springboot static resource path in Src/main/resources create/static or/public or/resources or/meta-inf/resources can directly access static resources, The default is placed in the Classpath directory

Scenario 2, through the application.properties configuration spring.resources.static-locations=classpath:/img/Specify the directory location of the custom static files, and multiple separated by commas, Springboot Automatic invalidation

Scenario 3, creating Staticcontroller class inheritance Webmvcconfigureradapter overriding addresourcehandlers specifying static access to the resource directory

Addresourcehandler represents the interception request, if encountered/IMG request will find the location of the corresponding resource in classpath:/img/, find the picture, if not found on the return 404 error

Addresourcelocations mapping path for accessing local resource content

The above is a small series to introduce you to the Springboot static resources css,js,img configuration scheme, I hope we have some help, if you have any questions please give me a message, small series will promptly reply to you. Thank you very much for the support of the Scripting House website!

Original link: http://www.toutiao.com/a6428064889595871490/

Spring-boot integration Freemarker introduced static resources CSS, JS, etc. (Turn)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.