In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces "does Spring Boot modify static resources have to restart the project to take effect?" The relevant knowledge, in the actual case operation process, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
Review hot deployment
I believe everyone has used the hot deployment in Spring Boot. You can easily achieve hot deployment by adding spring-boot-devtools dependencies. The most critical principle of hot deployment in Spring Boot is two different classloader:
Base classloader
Restart classloader
Base classloader is used to load classes that will not change, such as third-party dependencies, while restart classloader is used to load classes that will change, such as your own code. The principle of hot deployment in Spring Boot is that when the code changes, base classloader remains the same, while restart classloader is discarded and replaced by a new restart classloader. Throughout the process, because only the changed classes are reloaded, the startup speed is restarted quickly.
But there is another problem, which is static resource files! With devtools, the project restart is not triggered by default when static resources change. Although we can solve this problem through configuration, it is not necessary! Because the static resource file does not need to be compiled after the change, it can be accessed by refreshing after saving.
So how can it be automatically refreshed without compilation after a static resource change? LiveReload can help us achieve this function!
LiveReload
LiveReload server is embedded in devtools by default, and static files can be hot deployed with LiveReload. LiveReload can automatically trigger browser updates when resources change. LiveReload supports Chrome, Firefox and Safari. Take Chrome as an example, search for LiveReload in the Chrome App Store, and the results are as follows:
Add the first search result to Chrome. After adding it successfully, there is a LiveReload icon in the upper right corner of Chrome.
Open the project page in the browser, then click the LiveReload button in the upper right corner of the browser to open the LiveReload connection.
Note:
LiveReload is tied to the browser tab, and you can access the page in the tab where LiveReload is opened, so that it works.
After opening LiveReload, we start a Spring Boot project with devtools dependencies:
Org.springframework.boot spring-boot-devtools runtime true
At this point, feel free to add a static html page under the resources/static directory, then start the Spring Boot project and visit the html page in the tab that opens LiveReload.
After the visit is successful, we manually modify the code of the html page. After the modification is successful, we return to the browser. Without doing anything, we will find that the browser has been automatically refreshed and the page has been updated.
Throughout the process, my Spring Boot project did not restart.
If the developer installs and launches the LiveReload plug-in and adds devtools dependencies, but does not want the browser to refresh automatically when the static page changes, you can add the following code to application.properties to configure:
Spring.devtools.livereload.enabled=false "does Spring Boot modify static resources have to restart the project to take effect?" This is the end of the introduction, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.