【问题标题】:Spring Boot Developer Tools Auto restart doesn't work in IntelliJSpring Boot 开发人员工具自动重启在 IntelliJ 中不起作用
【发布时间】:2018-12-01 10:10:47
【问题描述】:

最近在 IntelliJ 中使用 spring-boot-devtools 启动了 spring-boot,并花了几个小时试图弄清楚为什么 IntelliJ 不会接受我的更改并自动重启嵌入式 tomcat。

此链接上的信息也没有帮助:https://dzone.com/articles/spring-boot-application-live-reload-hot-swap-with

【问题讨论】:

    标签: java spring spring-boot intellij-idea spring-boot-devtools


    【解决方案1】:

    为了让它工作,你需要:

    1) 在 maven 或 gradle 中启用 devtools。 在 Maven 中它看起来像:

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

    2)在IntellijIDEA中:进入settings(ctrl +alt+s) -> Build,Execution,Deployment -> compiler,勾选“Build project automatically”

    3) 在 IntellijIDEA 中:按 ctrl+shift+a 然后键入“registry”并单击它。然后启用选项“compiler.automake.allow.when.app.running”。

    4) 重新启动 intellijIDEA !!我因此失去了几个小时:/

    它现在应该可以工作了。

    请注意:

    -您不需要额外的路径或触发器文件即可按预期工作。

    -如果您使用 maven 启动参数 -Dspring-boot.run.fork=false 启用调试,则 devtools 被禁用,因此它不应在代码更改时重新启动。

    -在 yaml 文件中,您需要为来自 pom.xml 的参数使用引号。如果不这样做,项目将第一次运行,然后在重新启动时失败。

    spring:
      profiles:
        active: '@spring.profiles.active@'
    

    它适用于 INTELLIJIDEA 社区版,值得设置上限,因为许多答案说它只适用于终极版...

    【讨论】:

    • 很好,但它似乎有一个固定的时间来重新启动,而不是在进行修改时。
    【解决方案2】:

    通过将项目名称从 spring-boot 更改为 spring-boot-xxx(基本上除了 spring-boot 之外的任何东西),问题得到了解决。

    如果您仔细阅读文档,这里会提到:

    在决定类路径上的条目是否应在更改时触发重启时,DevTools 会自动忽略名为 spring-boot、spring-boot-devtools、spring-boot-autoconfigure、spring-boot 的项目-actuator 和 spring-boot-starter。

    使用 Ctrl+F9 构建项目会自动触发重新启动。如果您希望在保存类文件后​​立即自动触发,您可以点击问题中提供的热插拔链接。

    Spring Boot 还有一个选项可以在特定文件更改时触发重启,并且可以使用以下属性在 application.properties 中进行配置

    spring.devtools.restart.trigger-file=

    希望这可以帮助某人节省时间。

    【讨论】:

      猜你喜欢
      • 2019-06-26
      • 2015-12-14
      • 1970-01-01
      • 2019-07-13
      • 2021-07-15
      • 2017-12-14
      • 2010-11-17
      • 1970-01-01
      • 2015-02-27
      相关资源
      最近更新 更多