我在intellij 启动soringboot非常慢

在这里花了 WebApplicationContext: initialization completed in 316661 ms
下面是部分log。我项目没有debug断点。

22-07-22 23:38:53.455 []  [background-preinit] INFO  org.hibernate.validator.internal.util.Version:21 - HV000001: Hibernate Validator 6.2.0.Final
22-07-22 23:38:53.469 []  [main] INFO  StartApplication:55 - Starting StartApplication using Java 1.8.0_05 on DESKTOP-9OUGME0 with PID 14008 (D:\工作\other\springboot-base\core\target\classes started by maox in D:\工作\other\springboot-base)
22-07-22 23:38:53.470 []  [main] INFO  StartApplication:674 - The following profiles are active: dev
22-07-22 23:38:55.181 []  [main] INFO  o.s.d.r.config.RepositoryConfigurationDelegate:262 - Multiple Spring Data modules found, entering strict repository configuration mode!
22-07-22 23:38:55.185 []  [main] INFO  o.s.d.r.config.RepositoryConfigurationDelegate:132 - Bootstrapping Spring Data Redis repositories in DEFAULT mode.
22-07-22 23:38:55.214 []  [main] WARN  o.s.boot.autoconfigure.AutoConfigurationPackages:188 - @EnableAutoConfiguration was declared on a class in the default package. Automatic @Repository and @Entity scanning is not enabled.
22-07-22 23:38:55.217 []  [main] INFO  o.s.d.r.config.RepositoryConfigurationDelegate:201 - Finished Spring Data repository scanning in 8 ms. Found 0 Redis repository interfaces.
22-07-22 23:44:10.054 []  [main] INFO  o.s.boot.web.embedded.tomcat.TomcatWebServer:108 - Tomcat initialized with port(s): 8081 (http)
22-07-22 23:44:10.066 []  [main] INFO  org.apache.coyote.http11.Http11NioProtocol:173 - Initializing ProtocolHandler ["http-nio-8081"]
22-07-22 23:44:10.067 []  [main] INFO  org.apache.catalina.core.StandardService:173 - Starting service [Tomcat]
22-07-22 23:44:10.067 []  [main] INFO  org.apache.catalina.core.StandardEngine:173 - Starting Servlet engine: [Apache Tomcat/9.0.56]
22-07-22 23:44:10.215 []  [main] INFO  o.a.c.c.ContainerBase.[Tomcat].[localhost].[/ydxt]:173 - Initializing Spring embedded WebApplicationContext
22-07-22 23:44:10.215 []  [main] INFO  o.s.b.w.s.c.ServletWebServerApplicationContext:290 - Root WebApplicationContext: initialization completed in 316661 ms
22-07-22 23:44:10.267 []  [main] INFO  org.apache.catalina.core.StandardContext:173 - Suspicious URL pattern: [/**] in context [/ydxt], see sections 12.1 and 12.2 of the Servlet specification

开DEBUG级别的日志看看。

首先引入以下监控依赖

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
</dependencies>

修改启动类

@SpringBootApplication
public class MyApplication {

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(MyApplication.class);
        application.setApplicationStartup(new BufferingApplicationStartup(2048));
        application.run(args);
    }

}

配置文件配置

一定要*或者指定启动端点startup,不然访问404

management.endpoints.web.exposure.include=*

访问端点监控信息

127.0.0.1:19998/actuator/startup

寻找时间最长的

  • 第一步,看控制台中间有个大跳跃的时间值,那个是耗时最长的
  • 找到分秒,直接json里面检索即可,找到对应的启动信息,举例下面我的示例



2 Likes

你这个,都能单独写一篇教程了:如何通过spring-actuator找出启动耗时的Bean

可以的,我下午出一个

2 Likes