如何在 IntelliJ 2021.2 上启用 Spring Boot Live Dev Tools 在修改后重建类并将更改部署到服务器?

问题描述 投票:0回答:3

这是一个关于如何在 IntelliJ 2021.2 上启用 Dev Tools 项目并观察代码变化而无需重新启动 Tomcat 服务器的教程。

spring spring-boot intellij-idea
3个回答
43
投票

为了使其发挥作用,您需要:

  1. 在 maven 或 gradle 中启用 devtools。在 Maven 中它看起来像:
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
         <scope>runtime</scope><!-- -->
        <optional>true</optional>
    </dependency>
  1. 在 IntellijIDEA 中:转到设置(ctrl + alt+s) -> 构建、执行、部署 -> 编译器,选中“自动构建项目”

  2. 在“编译器”下的“设置”->“高级设置”中启用“即使开发的应用程序当前正在运行也允许自动启动”选项

check Allow auto-make to start even if developed application is currently running under Advanced Settings

您现在可以重新启动 IntelliJ IDE 并启动您的应用程序。


4
投票

1.文件->设置->构建、执行、部署->编译器->点击->自动构建项目->应用->确定

2.

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

3.文件->设置->高级选项->即使开发的应用程序正在运行,也允许自动启动->应用->确定

4.重启IDE


2
投票

设置您的项目和 IDE。

  1. 添加POM依赖。
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
  1. 在 IntellijIDEA 中:文件 -> 设置... -> 构建、执行、部署 -> 编译器:选中“自动构建项目”

  2. 在 IntellijIDEA 中:文件 -> 设置... -> 高级设置:选中“即使开发的应用程序当前正在运行,也允许自动启动”

设置您的浏览器。

  1. 将“LiveReload”扩展添加到您的浏览器。例如:如果您使用 Chrome 浏览器,请添加 livereload.com 的“LiveReload”扩展。

  2. 最初启动应用程序时,加载浏览器选项卡并将鼠标悬停在“LiveReload”扩展上以确保其已启用。工具提示应显示为“LiveReload 已连接,单击以禁用已访问此站点”。 LiveReload 工具提示

一旦设置完毕,确保自动重启和LiveReload;

  1. 对已运行的应用程序中的静态文件和 Java 文件进行更改。
  2. 构建项目(构建 -> 'Build Project' 或 Ctrl+F9)。
  3. 观察应用程序自动重新启动,并在 IDE 控制台中显示“LiveReload server is running on port ..”,并且浏览器刷新。
© www.soinside.com 2019 - 2024. All rights reserved.