![](/img/trans.png)
[英]Spring Boot maven project from Eclipse doesn't work in Intellij
[英]Spring Boot Developer Tools Auto restart doesn't work in IntelliJ
最近在 IntelliJ 中使用 spring-boot-devtools 启动了 spring-boot,并花了几个小时试图弄清楚为什么 IntelliJ 不会接受我的更改并自动重启嵌入式 tomcat。
此链接中的信息也没有帮助: https : //dzone.com/articles/spring-boot-application-live-reload-hot-swap-with
为了使其工作,您需要:
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中:进入设置(ctrl +alt+s)->构建、执行、部署->编译器,勾选“自动构建项目”
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 社区版,值得大写,因为许多答案说它只适用于终极...
通过将项目名称从 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=
希望这可以帮助某人节省时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.