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)