简体   繁体   English

IntelliJ IDEA 社区版和 Spring 使用 Spring DevTools 重新加载缓慢

[英]IntelliJ IDEA Community Edition and Spring slow reload with Spring DevTools

I know IDEA CE doesn't have support for Spring, but I still can develop with decent support for autocompletion, which is enough for me.我知道 IDEA CE 不支持 Spring,但我仍然可以在自动完成的良好支持下进行开发,这对我来说已经足够了。

The issue I have is that it takes 5 to 7 seconds for the IDE to reload the server with the changes I made after hitting Ctrl + S. So, I searched for more options I can modify, and I tried these:我遇到的问题是 IDE 需要 5 到 7 秒才能使用我在按 Ctrl + S 后所做的更改重新加载服务器。因此,我搜索了更多可以修改的选项,并尝试了这些:

在此处输入图像描述

But it doesn't solve the issue.但这并不能解决问题。

While I know I can use VSCode since the Java support is excellent and with Spring the reload is very fast, for Kotlin support there is no extension good enough.虽然我知道我可以使用 VSCode,因为 Java 支持非常好,并且 Spring 的重新加载非常快,但对于 Kotlin 支持,没有足够好的扩展。 So I'd like to find a fix to reduce the delay of the server restart, if possible.所以我想找到一个修复程序来减少服务器重启的延迟,如果可能的话。 It seems to be done on purpose to force you to buy the Professional edition.好像是故意逼你买专业版的。

You don't need to use automatic compilation or DevTools for IntelliJ IDEA Community or Ultimate to hotswap classes in Debug mode.您不需要使用自动编译或 DevTools for IntelliJ IDEA Community 或 Ultimate 在 Debug 模式下热交换类。 If you want to compile on Ctrl + S , assign this shortcut to Build |如果要在Ctrl + S上编译,请将此快捷方式分配给Build | Build Project action (Settings (Preferences on macOS) | Keymap | Main Menu | Build | Build Project, right click, Add Keyboard Shortcut ). Build Project操作(设置(macOS 上的首选项)| Keymap | Main Menu | Build | Build Project,右键单击,添加键盘快捷键)。

IDE will hotswap the changed classes and the changes will be available in the browser in less than a second: IDE 将热交换更改的类,更改将在不到一秒的时间内在浏览器中可用:

重新加载

Sample project: boot-hotswap-demo.zip .示例项目: boot-hotswap-demo.zip

Steps:脚步:

  1. Click Debug button to start the app单击调试按钮启动应用程序
  2. Open http://localhost:8080/ in the web browser在web浏览器中打开http://localhost:8080/
  3. Observe Greetings from Spring Boot!!!观察Greetings from Spring Boot!!! output output
  4. Change the string in HelloController.java to something elseHelloController.java中的字符串更改为其他内容
  5. Build |构建 | Build Project (or Ctrl + S if you assigned it to this action)构建项目(或Ctrl + S ,如果您将其分配给此操作)
  6. Reload the page in the browser, observe the changes in less than a second, IDE shows a notification about reloaded classes.在浏览器中重新加载页面,观察不到一秒的变化,IDE 显示有关重新加载类的通知。

You can also uncomment the spring-boot-devtools dependency in pom.xml if you want to rely on the DevTools and it will trigger the server restart on changes.如果你想依赖pom.xml ,你也可以取消注释 pom.xml 中的spring-boot-devtools依赖项,它会在更改时触发服务器重启。 It's a bit slower, but certainly not 5-7 seconds as you describe.它有点慢,但肯定不是你描述的 5-7 秒。

We use 2 annotation processors in our project: annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" and annotationProcessor "org.projectlombok:lombok".我们在项目中使用了 2 个注解处理器:annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" 和 annotationProcessor "org.projectlombok:lombok"。

Lombok works fine.龙目岛工作正常。 But if spring-boot-configuration-processor is active - hot swap always reload all classes, that takes more than minute on my project, much faster to restart app completely.但是,如果 spring-boot-configuration-processor 处于活动状态 - 热插拔总是重新加载所有类,这对我的项目来说需要超过一分钟,完全重启应用程序要快得多。

I comment that processor before start when I need hot swap.当我需要热插拔时,我会在启动前评论该处理器。

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

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