Objective
Because before using Myeclipes's classmates know, when using Myeclipes, Java files or JSP files will be directly loaded into the deployment of the container, so at the time of development, different often to restart the project, so as to achieve increased development efficiency.
But now after switching to Springboot, because there is no external container support, and using Gradle to build the project, plus the idea that the default does not automatically compile the features, and eventually lead to the development of projects need to restart the project frequently, this is what we do not want to see.
To improve the efficiency of development, we will optimize our springboot template below. The scheme has been verified and can be used with confidence.
GitHub Address: Https://github.com/LinkinStars/springBootTemplate
Programme description
1, Springboot for the page, has implemented a hot load, but the default is closed, need to open manually.
2, for Java class, use the spring-boot-devtools
official recommended to implement the thermal deployment (here is the thermal deployment is not the hot load note difference)
3, need to close the cache of the page, here I use the Thymeleaf configuration is explained later.
detailed scenario descriptions can be found in the Spring official documentation: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-hotswapping.html
Spring is really thoughtful, and I didn't see it at first. The documentation also has instructions for hot deployment.
How to configure the implementation
1. Add the Build.gradle file root node
Bootrun {
Turn on page hot load function
Addresources = True
}
2. Add under Build.gradle file dependencies compile ("Org.springframework.boot:spring-boot-devtools")
3. Open Idea Automatic compilation
After the above tick, press the key below
windows:ctrl + alt + shift + /
mac: command + alt + shift + /
Click Registry, Tick Compiler.automake.allow.when.app.running
4. Configure Thymeleaf.cache to False
Thymeleaf
Cache:false
Description of performance, etc.
1, after the above configuration, the page changes do not need to compile, the changes will be effective immediately
2, the Java class will be recompiled after modification, but note that the project will be re-deployed , you can see the information from the console.
3, but after testing, not the entire project re-deployment, spring should have been processed, so the time to redeploy very quickly , will not affect the use.
4, there is also a implementation of the scheme is used:springloaded is said to be the implementation of the hot load rather than hot deployment, but I after practice found in my environment is not successful, no effect, the spring Official document is also special to Springboot+gradle +idea such an environment using springloaded to explain, but I based on the document configuration is still not possible, may be related to my local environment, but the above configuration can meet my needs, and deployment time is not long, so I chose to use the Devtools
Https://docs.spring.io/spring-boot/docs/current/reference/html/howto-hotswapping.html
5, Happy also, because the implementation of the hot deployment, so even the modification of XML files, such as MyBatis SQL changes will be hot deployment , that is, to change what is immediately useful.
6, because currently is still one of the simplest projects, not many packages many classes, I do not know when the project is large after the deployment time will not be very long, also need to test. My advice is that if you have a lot of things to change at once, you just stop the project and change it. It's not that bad time anyway.
Springboot+gradle+idea for hot deployment and thermal loading