Hot swapping in Spring Boot

前端 未结 12 1538
别那么骄傲
别那么骄傲 2020-11-29 03:41

I\'ve been doing a P.O.C with Spring Boot.

So far it\'s been going really good and promising, but there\'s one major drawback: I\'m using an embedded server (i.e.,

相关标签:
12条回答
  • 2020-11-29 03:43

    try using this spring-boot-devtools tag in pom.xml

     <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <optional>true</optional>
            </dependency>
     </dependencies>
    

    http://mytechnologythought.blogspot.com/2017/07/how-to-run-server-of-spring-boot-auto.html

    0 讨论(0)
  • 2020-11-29 03:48

    There are several options. Running in an IDE (especially with debugging on) is a good way to do development (all modern IDEs allow reloading of static resources and usually also hotswapping of Java class changes). Spring Boot devtools is a cheap way to get quite a big boost (just add it to your classpath). It works by restarting your application in a hot JVM when changes are detected. It also switches off things like thymeleaf caches while it is running, so you don't have to remember to do that yourself. You can use it with an external css/js compiler process if you are writing that code with higher level tools.

    Spring Loaded is no longer recommended, but probably still in use. More sophisticated agent-based tools work much better if you need hot swapping with zero delay (e.g. JRebel).

    See the docs for some up to date content

    0 讨论(0)
  • 2020-11-29 03:54

    If you're using maven, the spring-boot-maven-plugin in your pom.xml needs to be like this to get the hot swap:

      <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <dependencies>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>springloaded</artifactId>
                    <version>1.2.0.RELEASE</version>
                </dependency>
            </dependencies>
        </plugin>
    

    and if you're using thymeleaf, add this to your application properties:

    spring.thymeleaf.cache=false
    

    But remember something: Don't use this in your production environment..

    0 讨论(0)
  • 2020-11-29 03:58

    but isn't there a built-in option of some sort when working with IntelliJ/Eclipse?

    What helped me in IntelliJ 15.0, windows 10, was the following sequence:

    STEP 1: Added the following dependency in pom (This is mentioned everywhere but this alone dint solve it), as mentioned by @jonashackt

    <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-devtools</artifactId>
    </dependency>
    

    STEP 2: Then from File->Settings-> Build-Execution-Deployment -> Compiler (make sure main compiler option is selected and not any of its sub-options)

    enable Make Project Automatically. Click ok and close the dialog Note : In latest version it will be Build project automatically

    STEP 3: Hold Shift+Ctrl+A (on windows) you will see a search dialog with title "Enter Action or option name", type registry. Double click the first option that says "Registry..." it will open another window. Look for the following option:

    compiler.automake.allow.when.app.running
    

    and enable it, click close

    STEP 4: Restart IDE

    Elaborated from this source

    0 讨论(0)
  • 2020-11-29 03:58

    You can also use JRebel - it will reload all changes (better hotswap) including spring beans. It is easily integratred with both Intellij and Eclipse.

    0 讨论(0)
  • 2020-11-29 03:59

    From 1.3.0. (now in Milestone 2) on, you can use the spring-boot-devtools for that as a lightweigt approach - see the docs or this blogpost. Simply upgrade to >= 1.3.0. and add the following to your pom.xml:

    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
      </dependency>
    </dependencies>
    

    Than start your SpringBootApplication with Run As... and you´re fine.

    0 讨论(0)
提交回复
热议问题