SpringBoot project development hot deployment settings (eclipse+gradle)

  Article time: 2018-01-04
  Author: wallimn
  Original address: //wallimn.iteye.com/blog/2406696

  Development environment: eclipse: Neon.3 Release (4.6.3), Gradle: 3.3

  Hot deployment of SpringBoot projects, also Just change the Java class or page file, without restarting the project, the modified content will take effect automatically. Looking at the articles on the Internet, the method is very simple, but I followed it, and it took a long time to get it right. Through repeated pondering, I figured out the relevant key.
  There are two ways to implement hot deployment. I use spring-boot-devtools.

1. Add support for spring-boot-devtools
  Modify the build.gradle file and add a reference to the class in the dependencies section.
dependencies {
// ……
    compile ('org.springframework.boot:spring-boot-devtools')
// ……
}

  Added a reference to the class, if (note that I mean if) the output location of the class file compilation result is correct, the hot deployment of the Java class file modification has been implemented.
  However, the location of the class file output by the eclipse environment does not match the location required by gradle, resulting in the hot deployment not taking effect.
  The next step is to modify the output location of the eclipse compilation results.

2. Modify the output location of the compilation result of the Java file
  Right-click on the project, properties->Java Build Path set the Default output folder, set it to the
project name (please replace it with your own project name) /build/classes/main
  to complete this modification, make sure Build Automatically is checked (Project menu-> Build Automatically), at this point, the hot deployment of Java files is achieved.

Third, the resource file (error)
  This problem is a bit complicated. Check the output of the eclipse console, find the monitoring path of devtools, and find that the location of the monitoring resource file is inconsistent with the location of the eclipse compilation result output. After research, it is found that the .classpath file in the project directory can be modified, and different output paths can be configured for the java file and resources file.
  I set the output path of the resources file to the
  project name (please replace it with your own project name) /build/resources/main
  but what is frustrating is that after observing the files in the result path, it is found that the html file used for testing does not pass Automatic compilation to update. I don't know why, if anyone knows, please let me know, thank you. I guess that if the resource file is modified, the corresponding file in the output directory will be automatically updated, which should be able to achieve hot deployment of the resource file.

4. Resource file (positive solution)
  Devtools has considered the problem of resource file and provided a solution. Modify the build.gradle file. Just add a sentence.
bootRun {
    addResources = true
}

  Observe the output of the eclipse console, you will find that the monitoring of the source directory of the resource file has been added. After testing, the hot deployment of the resource file has also been realized.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326391118&siteId=291194637