Idea上的SpringBoot的热部署配置, idea的自动编译设置

第一种:使用devtools的方式

这种其实是热启动. 也就是需要我们手动编译之后才能生效,普通的运行main方法启动项目

pom.xml加入依赖

<dependency>
  <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-devtools</artifactId>
   <scope>provided</scope>
   <optional>true</optional>
 </dependency>

可以通过event log来查看编译和更新日志

这里写图片描述

这里前提说一下, 我用的是idea.
1.需要complied编译之后才生效. 2. 需要是debug模式启动

eclipse是默认自动编译的,idea不是. 所以在设置热部署之前, 需要设置idea自动编译:

第二种: 使用springloaded插件

经过测试, 不需要手动编译, 就能生效., 用maven命令启动项目

<plugin>
   <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     <dependencies>
       <!-- spring热部署 -->
       <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>springloaded</artifactId>
         <version>1.2.6.RELEASE</version>
       </dependency>
     </dependencies>
     <configuration>
       <!--这里是main启动类的全路径-->
       <mainClass>cn.springboot.Mainspringboot</mainClass>
     </configuration>
   </plugin>

运行

$ mvn clean spring-boot:run

idea自动编译设置

1,设置File ->Setting ->Compile:

勾选图中的选项
这里写图片描述

2, 修改run/debug配置

Run->Edit Configurations

看图 在Before Launch下面的make去掉了。

或者在运行的Edit configuration中设置:
这里写图片描述

到了这里还要做一件事情,执行File->Invalidate Caches /Restart

到这里IDEA配置好了

但是自动编译也就意味者IDEA需要消耗更多的资源去实时监测代码改动,性能也会受到影响,而且如果我们希望的是在ctrl+s保存时自动编译,那也可以ctrl+f9来手动编译,或者点这个箭头
这里写图片描述

重新编译就行, 但是在类中添加新的方法不能热部署.

猜你喜欢

转载自blog.csdn.net/zzzgd_666/article/details/80379449
今日推荐