Spring-boot启动缓慢

use*_*637 13 jhipster

当我使用"mvn spring-boot:run"启动我的jhipster应用程序时,启动时间最多需要60秒...我的日志的第一部分是:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jhipster 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.1.9.RELEASE:run (default-cli) @ jhipster >>>
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-versions) @ jhipster ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ jhipster ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 22 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ jhipster ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ jhipster ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ jhipster ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.1.9.RELEASE:run (default-cli) @ jhipster <<<
[INFO]
[INFO] --- spring-boot-maven-plugin:1.1.9.RELEASE:run (default-cli) @ jhipster ---
[INFO] Attaching agents: []
Listening for transport dt_socket at address: 5005
Run Code Online (Sandbox Code Playgroud)

- >然后它会持续大约30秒,然后继续:

[INFO] com.mycompany.myapp.Application - Starting Application on MacBook-Pro.local with PID 5130 (/Users/othomas/Developpement/jhipster-1.9.0/target/classes started by othomas in /Users/othomas/Developpement/jhipster-1.9.0)
[DEBUG] com.mycompany.myapp.Application - Running with Spring Boot v1.1.9.RELEASE, Spring v4.0.8.RELEASE
[DEBUG] org.jboss.logging - Logging Provider: org.jboss.logging.Log4jLoggerProvider
Run Code Online (Sandbox Code Playgroud)

...

我记得曾使用过旧版本的jhipster发生器(0.17等),它开始时间为15-20秒.这是正常的还是我身边有问题?在哪里寻找?

谢谢,O.

Ben*_*ley 8

我自己一直在慢慢启动时间,并想知道原因是什么.我得到所有控制台消息,说各种事情已经开始,然后它在最终消息之前挂起,说应用程序已加载.

最终我发现我可以使用Java VisualVM作为JDK的一部分来查看发生了什么.如果你有jdk在bin文件夹中安装了jvisualvm.exe.然后,当我选择调试为Application.java时,会弹出tomcat进程,您可以跟踪正在发生的事情.

我把几个线程转储挂起来,似乎总是在生成swagger API文档的地方.更多挖掘,这是在名为MetricsConfiguration的类中配置的,如果您使用名为"fast"的配置文件运行,则会将其排除.

在eclipse中,我编辑了我的调试配置,以包含一个程序参数:

--spring.profiles.active=dev,fast
Run Code Online (Sandbox Code Playgroud)

这将启动时间从230秒减少到25秒!

我有一个快速扫描,快速似乎禁用各种事情.它主要看起来像管理菜单下的东西,无论如何你在开发过程中可能都不需要.就个人而言,我更喜欢快速启动,以便能够在开发过程中看到其余的文档.

Swagger就是这样一头猪,让我想知道这毕竟是不是一个好主意.值得花费吗?然后我读了这个http://java.dzone.com/articles/swagger-great,我正在考虑完全删除它.这是一个不错的主意,但似乎为构建添加了33mb +对我来说导致启动时间非常慢.

有关信息,我有大约16个实体.所以不小但不过分大.


Jan*_*nik 5

确保您没有在调试模式下运行服务器并且设置了断点。这将我的一个应用程序的启动时间从 3 分钟减少到 22 秒。


Jul*_*ois 0

这很奇怪。事实上,它应该在 5-15 秒内启动,具体取决于您的机器和具体设置。但它不应该挂起 30 秒:您显示的行有点新,这是因为当您使用开发配置文件时我们以调试模式启动应用程序 - >您可以在其上附加调试器。看起来它正在等待您连接调试器:我自己从未见过它,所以也许您有一些特定的 JVM 选项用于在启动时附加调试器,超时时间为 30 秒?