Hot swapping in Spring Boot

前端 未结 12 1546
别那么骄傲
别那么骄傲 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 04:00

    You can get hot swapping:

    • for java code: using spring-loaded
    • for Thymeleaf templates: disabling the cache

    Check this post to see more details: http://blog.netgloo.com/2014/05/21/hot-swapping-in-spring-boot-with-eclipse-sts/

    0 讨论(0)
  • 2020-11-29 04:01

    I do not know how far this kind of support goes, but in case you use Eclipse IDE (or anyone reading this): starting up your Spring-Boot application via m2e in debug-mode (press the "Debug"-dropdown button and pick your maven run configuration item).

    It works for me like a charm.

    My maven run configuration item is configured as follows:

    • goal is set to "spring-boot:run"
    • base directory is the project directory

    I am not using any further libraries (not even spring-boot-devtools).

    That's it.

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

    In Intellij, I can get this behavior. When the program is running in debug mode, select Run > Reload Changed Classes

    Note: After Intellij completes the action, it might say Loaded classes are up to date. Nothing to reload. This is misleading, because it actually DID reload your classpath resources.

    My environment/setup includes:
    Intellij 13
    Embedded Tomcat
    Run/Debug configuration of type 'Application' (which just uses a main class)
    Serving static html, css and js (no jsp)

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

    I recommend Thymeleaf (template engine), jRebel for personal developer. Thymeleaf template files are just HTML resources. So, they`re changed immediately after you edit template files.

    0 讨论(0)
  • 2020-11-29 04:08

    How to perform Hot Swap in Springboot Application

    1. When using gradle include following in the dependency: compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.0.1.RELEASE' & providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')

    2. In application.properties add the property spring.devtools.restart.additional-paths=.

    3. Build Gradle and then run application as bootRun

    The application is ready to perform hot swap on modification of classes

    0 讨论(0)
  • 2020-11-29 04:09

    Assuming you are using gradle; use the following config in your build.gradle

    apply plugin: 'java'
    apply plugin: 'idea'
    apply plugin: 'spring-boot'
    apply plugin: 'application'
    
    applicationDefaultJvmArgs = ["-agentlib:jdwp=transport=dt_socket,address=localhost:7000,server=y,suspend=n"]
    
    mainClassName = "package.ApplicationRunner"
    

    Run the application from the IDE or command line using the command gradle build run

    Now the IDE can connect to the remote JVM (on port 7000) where the spring boot application runs. It also supports hot deployment of static files.

    or even you can run the main class from intelliJ if the dependencies are properly managed in the IDE. The main class is the class that contains the main method which will call SpringApplication.run("classpath:/applicationContext.xml", args);

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