Home> Java> javaTutorial> body text

How Spring Boot implements hot deployment

angryTom
Release: 2020-02-14 14:31:40
Original
5662 people have browsed it

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

 org.springframework.boot spring-boot-devtools true 
Copy after login

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/**
Copy after login

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 PROPERTIES; static { Map properties = new HashMap(); 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); }
Copy after login

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 toPHP 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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!