SoFunction
Updated on 2025-05-14

spring boot several ways and configuration methods to implement hot deployment

1. Built-in hot deployment of development tools (recommended)

1. Spring DevTools principle:

Implemented based on two class loaders: the basic class loader (loading classes that do not change, such as third-party dependencies) and the restart class loader (loading application code). When the file is modified, the restart class loader will be reloaded to achieve a fast restart.

Configuration steps

<!-- Maven -->
<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>

Trigger method
After modifying the file, restart will be automatically triggered when the IDE is saved (default monitoringsrc/main/resourcesandsrc/main/java)。

Things to note

  • The production environment needs to be disabled (through=false)。
  • Static resource modification does not require restart and will take effect automatically.

2. IDE hot deployment (such as IntelliJ IDEA)

Configuration steps

  • Enable automatic compilation:File > Settings > Build, Execution, Deployment > Compiler > Build project automatically
  • Allow the class to be reloaded at runtime:Ctrl + Shift + Alt + /,chooseRegistry, check

Trigger method
After modifying the code, pressCtrl + F9(Recompile) orCtrl + Shift + F9(Recompile specific classes).

2. JRebel plug-in (commercial/paid)

principle:

  • Through bytecode enhancement technology, class definitions are dynamically updated without restarting the JVM, supporting real-time update of code, configuration and resources.

advantage

  • No restart required, extremely fast response speed (millisecond level).
  • Supports breakpoint debugging and complex code changes (such as new methods and fields).

Configuration steps

  • Install JRebel Plugin (IDE Plugin Market Search Install).
  • Activate and configure the project (Run > Edit Configurations > Add JRebel agent)。

3. Docker container hot deployment

principle
Use Docker's Volume Mount to map local code into containers, and combine Spring DevTools to achieve code updates in containers.

Configuration steps

# 
version: '3'
services:
  app:
    build: .
    ports:
      - "8080:8080"
    volumes:
      - ./src:/app/src  # Mount source code    environment:
      - SPRING_DEVTOOLS_RESTART_ENABLED=true

Trigger method
After modifying the local code, the files in the container are updated synchronously, triggering Spring DevTools to restart.

4. Custom class loader (advanced solution)

principle
Custom class loaders implement dynamic loading of specific classes, which are suitable for scenarios with extremely high performance requirements.

Implementation example

public class CustomClassLoader extends URLClassLoader {
    public CustomClassLoader(URL[] urls, ClassLoader parent) {
        super(urls, parent);
    }
    @Override
    public Class&lt;?&gt; loadClass(String name) throws ClassNotFoundException {
        // Custom class loading logic        if (("")) {
            return findClass(name);
        }
        return (name);
    }
}

Things to note
The implementation is complex and requires class loading conflicts and memory leaks.

5. Remote debugging (production environment hot repair)

principle
Remote debugging via JVM-agentlib:jdwp), combined with the remote debugging mode of the IDE, dynamically modify the running code.

Configuration steps

Add JVM parameters when starting the application:

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar 

Configure remote debugging in the IDE (Run > Edit Configurations > Remote)。

Applicable scenarios
The production environment urgently repairs minor problems, but it is necessary to operate with caution to avoid affecting service stability.

Comparison and selection suggestions

Way Applicable scenarios Restart speed Difficulty to achieve Support breakpoint Available in production environment
Spring DevTools Development Environment Seconds Low yes no
IDE hot deployment Rapid iterative development Seconds Low yes no
JRebel Efficient development of large-scale projects Millisecond level middle yes no
Docker container hot deployment Container development testing Seconds middle yes no
Custom class loader High-performance framework development Millisecond level high no no
Remote debugging Emergency repair of production environment No restart high yes Use with caution

Recommended combination plan

  • Development stage: Spring DevTools + IDE automatically compiled.
  • Complex projects: JRebel + unit test.
  • Production environment: Use Docker multi-instance deployment to quickly release new versions through CI/CD.

This is the end of this article about several ways to implement hot deployment in spring boot. For more related hot deployment content in spring boot, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!