简体   繁体   English

Spring Boot 开发人员工具自动重启在 IntelliJ 中不起作用

[英]Spring Boot Developer Tools Auto restart doesn't work in IntelliJ

Started spring-boot with spring-boot-devtools recently in IntelliJ and spent couple of hours trying to figure out why IntelliJ would not pick up my changes and auto restart embedded tomcat.最近在 IntelliJ 中使用 spring-boot-devtools 启动了 spring-boot,并花了几个小时试图弄清楚为什么 IntelliJ 不会接受我的更改并自动重启嵌入式 tomcat。

Information at this link didn't help either: https://dzone.com/articles/spring-boot-application-live-reload-hot-swap-with此链接中的信息也没有帮助: https : //dzone.com/articles/spring-boot-application-live-reload-hot-swap-with

In order to make it work, you need to:为了使其工作,您需要:

1)Have devtools enable in maven or gradle. 1) 在 maven 或 gradle 中启用 devtools。 In maven it looks like :在Maven中它看起来像:

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

2)In IntellijIDEA: go in settings(ctrl +alt+s) -> Build,Execution,Deployment -> compiler, check "Build project automatically" 2)在IntellijIDEA中:进入设置(ctrl +alt+s)->构建、执行、部署->编译器,勾选“自动构建项目”

3)In IntellijIDEA: press ctrl+shift+a then type "registry" and click on it. 3)在 IntellijIDEA 中:按 ctrl+shift+a,然后输入“registry”并单击它。 Then enable the option "compiler.automake.allow.when.app.running".然后启用选项“compiler.automake.allow.when.app.running”。

4) RESTART intellijIDEA !! 4)重新启动intellijIDEA! I lost few hours because of this :/因为这个,我失去了几个小时:/

It should now be working.它现在应该可以工作了。

Please note that:请注意:

-You don't need additional-paths or trigger-file for this to work as intended. - 您不需要附加路径或触发器文件即可按预期工作。

-If you are using the maven launch parameter -Dspring-boot.run.fork=false to enable debugging, then devtools are disabled, so it should not reboot on code change. - 如果您使用 maven 启动参数-Dspring-boot.run.fork=false来启用调试,则 devtools 被禁用,因此不应在代码更改时重新启动。

-in the yaml file, you need to use quotes for parameters coming from the pom. - 在 yaml 文件中,您需要对来自 pom.xml 的参数使用引号。 If you don't, the project will run the first time and then fail on reboot.如果不这样做,该项目将第一次运行,然后在重新启动时失败。

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

IT WORKS WITH INTELLIJIDEA COMMUNITY EDITION, it's worth the caps as many answers say it works only with ultimate...它适用于 INTELLIJIDEA 社区版,值得大写,因为许多答案说它只适用于终极...

The issue was resolved by changing the name of the project from spring-boot to spring-boot-xxx (basically anything but spring-boot).通过将项目名称从 spring-boot 更改为 spring-boot-xxx(基本上除了 spring-boot 之外的任何内容)解决了该问题。

If you read the documentation carefully here's what is mentioned:如果您仔细阅读文档,这里提到的是:

When deciding if an entry on the classpath should trigger a restart when it changes, DevTools automatically ignores projects named spring-boot , spring-boot-devtools, spring-boot-autoconfigure, spring-boot-actuator, and spring-boot-starter.在决定类路径上的条目是否应在更改时触发重新启动时,DevTools 会自动忽略名为spring-boot 、spring-boot-devtools、spring-boot-autoconfigure、spring-boot-actuator 和 spring-boot-starter 的项目。

Building the project using Ctrl+F9 automatically triggers a restart.使用 Ctrl+F9 构建项目会自动触发重新启动。 If you wish to automatically trigger as soon as a class file is saved you can follow the hot-swap link provided in the question.如果您希望在保存类文件后​​立即自动触发,您可以按照问题中提供的热插拔链接进行操作。

Spring Boot also has an option to trigger restart when a specific file changes and that can be configured in application.properties using following property Spring Boot 还具有在特定文件更改时触发重启的选项,并且可以使用以下属性在 application.properties 中进行配置

spring.devtools.restart.trigger-file= spring.devtools.restart.trigger-file=

Hope this helps someone save time.希望这可以帮助某人节省时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM