search
HomeJavajavaTutorialHow Spring Boot implements hot deployment

How Spring Boot implements hot deployment

Feb 14, 2020 pm 02:31 PM
spring bootHot deployment

How Spring Boot implements hot deployment

How to implement hot deployment in Spring Boot

It is a very simple thing to implement hot deployment of code in Spring Boot, and the code modification can be automatically Deploy and restart the project.

1. Quote the devtools dependency

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

In this way, when a java class is modified, it will be hot updated.

2. Customized configuration hot deployment

The following configuration is used for customized configuration hot deployment and does not need to be set.

# 热部署开关,false即不启用热部署
spring.devtools.restart.enabled: true
# 指定热部署的目录
#spring.devtools.restart.additional-paths: src/main/java
# 指定目录不更新
spring.devtools.restart.exclude: test/**

3. Intellij Idea modification

If it is an idea, you need to change the following two places:

1. Check automatic compilation or manually re-compile Compile

File > Settings > Compiler-Build Project automatically

2, Register

ctrl shift alt / > Registry > Check Compiler autoMake allow when app running

Notes

1. The production environment devtools will be disabled, such as java -jar mode or custom class loader, etc. will be recognized for a production environment.

2. Packaged applications will not include devtools by default unless you disable the excludeDevtools attribute of the SpringBoot Maven plug-in.

3. Thymeleaf does not need to configure spring.thymeleaf.cache: false. devtools will automatically set it by default. Click to refer to the complete properties.

The following is part of the source code for the automatic configuration of devtools:

@Order(Ordered.LOWEST_PRECEDENCE)
public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostProcessor {
    private static final Map<String, Object> PROPERTIES;
    static {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("spring.thymeleaf.cache", "false");
        properties.put("spring.freemarker.cache", "false");
        properties.put("spring.groovy.template.cache", "false");
        properties.put("spring.mustache.cache", "false");
        properties.put("server.session.persistent", "true");
        properties.put("spring.h2.console.enabled", "true");
        properties.put("spring.resources.cache-period", "0");
        properties.put("spring.resources.chain.cache", "false");
        properties.put("spring.template.provider.cache", "false");
        properties.put("spring.mvc.log-resolved-exception", "true");
        properties.put("server.jsp-servlet.init-parameters.development", "true");
        PROPERTIES = Collections.unmodifiableMap(properties);
    }

4. Devtools will occupy the java process in the Windows Resource Manager and cannot be killed in the development tools. It can only be killed manually, otherwise After restarting, the port will be selected for repeated binding and an error will be reported.

For more related content, please pay attention to PHP Chinese website.

The above is the detailed content of How Spring Boot implements hot deployment. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor