前言:

每次修改一丢丢东西都要重启是不是很费时间很糟心,热部署的好处神马的简直不用多说,往下看。


1.修改pom

加依赖:

    <!-- 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

加启动设置:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <fork>true</fork>
            </configuration>
        </plugin>
    </plugins>
</build>

2.设置Idea自动build

Spring Boot 学习之路——2 热部署


清缓存,重启:

Spring Boot 学习之路——2 热部署

网上有教程说要设置Ctrl+Shift+Alt+/ => Register => 找到并勾选compiler.automake.allow.when.app.running

我进入Register 页面就没有这个选项,网上一查到说是因为我用的版本2018.1比较新,根本不用这步,经过上一步设置Idea自动build,再重启之后,Ctrl+Shift+Alt+/ => Register 可以看到这个选项已经勾上了。

Spring Boot 学习之路——2 热部署


3.测试

启动DemoApplication之后,修改SayHello 

@RequestMapping(value = "/humanSays", method = RequestMethod.GET)
public String humanSays(@RequestParam(name = "name", required = false) String name,
                        @RequestParam(name = "comeFrom", required = false) String comeFrom) {
    return "Hello " + name + ", who comes from " + comeFrom + ", I'm a human , hahaha";
}

可以看到改完后Console立刻就打印日志重启了


再次访问:http://localhost:8080/sayHello/humanSays?name=Joanna&comeFrom=China   

可以看到页面输出:Hello Joanna, who comes from China, I'm a human , hahaha


成功!~


相关文章:

  • 2021-06-24
  • 2022-12-23
  • 2021-10-11
  • 2021-08-12
  • 2021-06-24
  • 2021-05-28
  • 2021-09-28
猜你喜欢
  • 2021-06-17
  • 2021-04-25
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
相关资源
相似解决方案