1.  必须重启
    目前的Springboot,当发生了任何修改之后,必须关闭后再启动Application类才能够生效,显得略微麻烦。 Springboot提供了热部署的方式,当发现任何类发生了改变,马上通过JVM类加载的方式,加载最新的类到虚拟机中。 这样就不需要重新启动也能看到修改后的效果了
  2.  pom.xml
    做法很简单,在pom.xml中新增加一个依赖就行了
     
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
    </dependency>
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
     
      <groupId>com.how2java</groupId>
      <artifactId>springboot</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <name>springboot</name>
      <description>springboot</description>
      <packaging>war</packaging>
       
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.9.RELEASE</version>
        </parent>
     
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>3.8.1</version>
                  <scope>test</scope>
            </dependency>
            <!-- servlet依赖. -->
            <dependency>
                  <groupId>javax.servlet</groupId>
                  <artifactId>javax.servlet-api</artifactId>
                  <scope>provided</scope>
            </dependency>
                  <dependency>
                         <groupId>javax.servlet</groupId>
                         <artifactId>jstl</artifactId>
                  </dependency>
            <!-- tomcat的支持.-->
            <dependency>
                   <groupId>org.apache.tomcat.embed</groupId>
                   <artifactId>tomcat-embed-jasper</artifactId>
                   <scope>provided</scope>
            </dependency>    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
            </dependency>
             
        </dependencies>
     
        <properties>
            <java.version>1.8</java.version>
        </properties>
     
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
     
    </project>
  3. 重启测试
    重新启动Application,然后随便修改一下HelloController, 就会如图所示观察到控制台的自动重启现象











Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐