千峰商城-springboot项目实战08-热部署配置

项目首次部署,服务启动之后,如果项目发生变化,而且IDEA感知到了应用的变化,就自动的完成jar的更新,无需手动再次启动服务器,就可以访问应用的更新。

 

热部署配置:

 

1.IDE配置(idea)

 

File --->  settings

 

 

Build --->  Compiler ---> 勾选 Build project automatically(自动项目构建)---> Apply  --->  OK

 

 

 

 键盘按键 :  Ctrl + Shift + Alt + /     出现如下窗口。点击Registry。

 

 

 

找到此项,选中。关闭。

 

 

 

修改成功之后再次 Ctrl + Shift + Alt + /     ,点击Registry,此项变成蓝色!

 

 

 

 

2.SpringBoot项目配置。

在需要进行热部署的springboot项目中添加依赖。

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <version>2.6.7</version>
        </dependency>

 

在pom.xml的标签<build>中的<configuration>中添加:<fork>true</fork>

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

 

3.

点击项目的Application  ——>  点击 Edit Configurations。

 

在当前Application中,在 On 'Update' action (当项目发生改动时) ,选择 Update classes and resources (自动更新类和资源)--->Apply  --->OK

 

 

 4.测试

启动应用。清空控制台。

 

 

在BookController.java中添加删除方法:

   @RequestMapping("/delete")
    public String deleteBook(int bookId){
        System.out.println("------delete");
        return "a";
    }

 

添加完成后跳转到其他类。发现应用进行了自动热部署。

 

 

 

 

 
 
posted @ 2022-04-26 23:23  临易  阅读(35)  评论(0编辑  收藏  举报