Implementing hot deployment of code in Spring Boot is a simple matter, and code changes can be automatically deployed and relaunched.

Reference devTools dependencies

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

This way, when a Java class is modified, it will be hot updated.

Customize hot deployment configurations

The following configuration is used for user-defined hot deployment and is optional.

# hot deployment switch, false or not enable hot deploy spring. Devtools. Restart. Enabled: true # # specifies the directory in which the hot deployment spring. Devtools. Restart. Additional - paths: SRC/main/Java. # specified directory is not update the spring devtools. Restart. Exclude: test / * *Copy the code

Intellij Idea change

For IDEA, the following two points need to be changed:

1. Check automatic or manual recompile

File > Settings > Compiler-Build Project automatically

2, registered

CTRL + Shift + Alt + / > Registry > Check Compiler autoMake allow when APP Running

Matters needing attention

Devtools will be disabled in production environment, such as Java-JAR or custom class loaders will be recognized as production environment.

2. Devtools is not included by default unless you disable the excludeDevtools attribute of the SpringBoot Maven plugin.

Thymeleaf. cache: false. Devtools will set it automatically by default.

Here is the source code for devTools automatic configuration:

@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); }Copy the code

4, DevTools will occupy the Java process in Windows Explorer, in the development tool can not kill, you must manually kill, otherwise the restart will be selected as port repeated binding error.

For more details on boot-devTools, please refer to the official documentation.

Recommended reading

Dry goods: 2TB architect four-stage video tutorial

Interview: the most complete Java multithreaded interview questions and answers

Interview: the most comprehensive ali advanced Java interview questions in history

Interview: The most complete Spring interview questions in history

Tutorial: The most complete Spring Boot complete video tutorial

Books: 15 must-read books for advanced Java architects

Tools: Recommended an online creation flow chart, mind mapping software

Share Java dry goods, high concurrency programming, hot technology tutorials, microservices and distributed technology, architecture design, blockchain technology, artificial intelligence, big data, Java interview questions, and cutting-edge hot news.