使用Spring Data运行Spring Native Application需要大约2-3秒的启动时间



我已经用Spring Initializr创建了一个Spring Boot应用程序。我将Spring Data与MySQL JDBC连接一起使用。我用gradle bootBuildImage创建了一个docker映像,并用docker run --rm -p 8080:80 buchschrank:0.0.1-SNAPSHOT启动了这个docker映像。但启动需要大约2-3秒,而不是几毫秒:

2021-11-09 16:03:32.238  INFO 1 --- [           main] o.s.nativex.NativeListener               : This application is bootstrapped with code generated with Spring AOT
.   ____          _            __ _ _
/\ / ___'_ __ _ _(_)_ __  __ _    
( ( )___ | '_ | '_| | '_ / _` |    
\/  ___)| |_)| | | | | || (_| |  ) ) ) )
'  |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::                (v2.5.6)
2021-11-09 16:03:32.277  INFO 1 --- [           main] o.s.boot.SpringApplication               : Starting application using Java 11.0.13 on 2b2e5a51334b with PID 1 (started by cnb in /workspace)
2021-11-09 16:03:32.277  INFO 1 --- [           main] o.s.boot.SpringApplication               : No active profile set, falling back to default profiles: default
2021-11-09 16:03:32.326  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-11-09 16:03:32.329  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 2 ms. Found 1 JPA repository interfaces.
2021-11-09 16:03:32.388  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 80 (http)
2021-11-09 16:03:32.389  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-11-09 16:03:32.389  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.54]
2021-11-09 16:03:32.395  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-11-09 16:03:32.395  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 116 ms
2021-11-09 16:03:32.412  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-11-09 16:03:32.414  INFO 1 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.32.Final
2021-11-09 16:03:32.415  INFO 1 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-11-09 16:03:32.417  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-11-09 16:03:33.840  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-11-09 16:03:33.842  INFO 1 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2021-11-09 16:03:34.973  INFO 1 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-11-09 16:03:34.974  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-11-09 16:03:35.033  WARN 1 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-11-09 16:03:35.077  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 80 (http) with context path ''
2021-11-09 16:03:35.078  INFO 1 --- [           main] o.s.boot.SpringApplication               : Started application in 2.852 seconds (JVM running for 2.854)

我的示例应用程序的源代码:https://github.com/lesestunden/buchschrank-backend

知道我的应用程序设置出了什么问题吗?非常感谢!

原因是与数据库的初始连接缓慢。在本地运行mysql数据库的情况下,启动时间约为200ms。

最新更新