zoukankan      html  css  js  c++  java
  • 【SpringBoot】SpringBoot 热部署(二十七)

      在开发中我们修改一个Java文件后想看到效果不得不重启应用,这导致大量时间花费,我们希望不重启应用的情况下,程序可以自动部署(热部署)。有以下四种情况,如何能实现热部署。

    1、模版引擎

      1)在Spring Boot中开发情况下禁用模板引擎的cache

      2)页面模板改变ctrl+F9可以重新编译当前页面并生效

    2、Spring Loaded

      Spring官方提供的热部署程序,实现修改类文件的热部署

      下载Spring Loaded(项目地址https://github.com/spring-projects/spring-loaded)

      添加运行时参数;

        -javaagent:C:/springloaded-1.2.5.RELEASE.jar –noverify

    3、JRebel

      1)收费的一个热部署软件

      2)安装插件使用即可

    4、Spring Boot Devtools(推荐)

      1)引入依赖

    1 <dependency>
    2     <groupId>org.springframework.boot</groupId>
    3     <artifactId>spring-boot-devtools</artifactId>
    4     <optional>true</optional>
    5 </dependency>

      2)项目启动时重新编译(IDEA使用ctrl+F9)

      测试devtools

      a、新建SpringBoot Web项目,依赖如下:

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0"
     3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     5     <modelVersion>4.0.0</modelVersion>
     6 
     7     <groupId>com.test</groupId>
     8     <artifactId>test-springboot-devtools</artifactId>
     9     <version>1.0-SNAPSHOT</version>
    10 
    11 
    12     <parent>
    13         <groupId>org.springframework.boot</groupId>
    14         <artifactId>spring-boot-starter-parent</artifactId>
    15         <version>2.1.8.RELEASE</version>
    16     </parent>
    17 
    18     <properties>
    19         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    20         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    21         <java.version>1.8</java.version>
    22     </properties>
    23 
    24     <dependencies>
    25         <dependency>
    26             <groupId>org.springframework.boot</groupId>
    27             <artifactId>spring-boot-starter-web</artifactId>
    28         </dependency>
    29 
    30         <dependency>
    31             <groupId>org.springframework.boot</groupId>
    32             <artifactId>spring-boot-starter-thymeleaf</artifactId>
    33         </dependency>
    34 
    35         <dependency>
    36             <groupId>org.springframework.boot</groupId>
    37             <artifactId>spring-boot-devtools</artifactId>
    38             <optional>true</optional>
    39         </dependency>
    40 
    41         <dependency>
    42             <groupId>org.springframework.boot</groupId>
    43             <artifactId>spring-boot-starter-test</artifactId>
    44             <scope>test</scope>
    45         </dependency>
    46 
    47     </dependencies>
    48 
    49 
    50     <!-- SpringBoot打包插件,可以将代码打包成一个可执行的jar包 -->
    51     <build>
    52         <plugins>
    53             <plugin>
    54                 <groupId>org.springframework.boot</groupId>
    55                 <artifactId>spring-boot-maven-plugin</artifactId>
    56             </plugin>
    57         </plugins>
    58     </build>
    59 </project>
    pom.xml

      b、编辑一个controller,如下:

    1 @Controller
    2 public class HelloController {
    3 
    4     @RequestMapping("/hello")
    5     public String hello(){
    6         return "hello";
    7     }
    8

      c、编译一个页面hello.html

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Title</title>
     6 </head>
     7 <body>
     8     <h3>Hello World!!!</h3>
     9 </body>
    10 </html>

      d、启动项目,使用地址http://localhost:8080/hello,访问界面

        

      • 修改页面内容,Hello World!!! --》World!!!,ctrl+F9重新编译项目,查看显示内容
      • 修改controller映射路径,/hello --》/abc,ctrl+F9重新编译项目,查看显示内容

      

  • 相关阅读:
    XVIII Open Cup named after E.V. Pankratiev Stage 5: Eastern Grand Prix
    XX Russia Team Open, High School Programming Contest St Petersburg, Barnaul, Tbilisi, Almaty, Kremenchug, November 30, 2019
    2019-2020 ICPC, NERC, Northern Eurasia Finals
    The 2019 China Collegiate Programming Contest Harbin Site
    Southeastern European Regional Programming Contest 2019
    2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)
    2019-2020 Saint-Petersburg Open High School Programming Contest (SpbKOSHP 19)
    hdu6354 Everything Has Changed (圆的相交弧长)
    hdu6341 Problem J. Let Sudoku Rotate (dfs)
    hdu6333 Problem B. Harvest of Apples(组合数+莫队)
  • 原文地址:https://www.cnblogs.com/h--d/p/12520537.html
Copyright © 2011-2022 走看看