升級macOS Big Sur後spring boot 項目啓動緩慢

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.3)

2021-03-04 10:22:05.930  INFO 31377 --- [           main] c.loyin.solar.SolarApplication   : Starting SolarApplication using Java 1.8.0_261 on lareinadeiMac.local with PID 31377 (/Users/liushengfeng/workspace/solar_monitor/solar_server_sb/target/classes started by liushengfeng in /Users/liushengfeng/workspace/solar_monitor/solar_server_sb)
2021-03-04 10:22:05.933  INFO 31377 --- [           main] c.loyin.solar.SolarApplication   : No active profile set, falling back to default profiles: default
2021-03-04 10:22:06.680  WARN 31377 --- [           main] io.undertow.websockets.jsr               : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2021-03-04 10:22:06.697  INFO 31377 --- [           main] io.undertow.servlet                      : Initializing Spring embedded WebApplicationContext
2021-03-04 10:22:06.700  INFO 31377 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 690 ms
2021-03-04 10:22:06.861  INFO 31377 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-04 10:22:06.997  INFO 31377 --- [           main] io.undertow                              : starting server: Undertow - 2.2.4.Final
2021-03-04 10:22:07.004  INFO 31377 --- [           main] org.xnio                                 : XNIO version 3.8.0.Final
2021-03-04 10:22:07.011  INFO 31377 --- [           main] org.xnio.nio                             : XNIO NIO Implementation Version 3.8.0.Final
2021-03-04 10:22:07.081  INFO 31377 --- [           main] org.jboss.threads                        : JBoss Threads version 3.1.0.Final
2021-03-04 10:22:07.138  INFO 31377 --- [           main] o.s.b.w.e.undertow.UndertowWebServer     : Undertow started on port(s) 8080 (http)
2021-03-04 10:22:07.148  INFO 31377 --- [           main] c.loyin.solar.SolarApplication   : Started SolarApplication in 1.58 seconds (JVM running for 1.887)

在構建一個空spring-boot項目時,從日誌看出運行時間太久。

日誌如下:

2021-03-04 10:20:27.945  WARN 31120 --- [           main] o.s.boot.StartupInfoLogger               : InetAddress.getLocalHost().getHostName() took 5001 milliseconds to respond. Please verify your network configuration (macOS machines may need to add entries to /etc/hosts).

....

2021-03-04 10:20:34.146  INFO 31120 --- [           main] o.s.b.w.e.undertow.UndertowWebServer     : Undertow started on port(s) 8080 (http)
2021-03-04 10:20:34.154  INFO 31120 --- [           main] c.loyin.solar.SolarApplication   : Started SolarApplication in 21.578 seconds (JVM running for 22.05)

從第一條日誌可以看出是hots解析的問題。

解決方法如下:

hostname #查看當前hostname

編輯hosts

sudo vim /etc/hosts

將上面hostsname配置到hosts

127.0.0.1       localhost       lareinadeiMac.local
::1             localhost       lareinadeiMac.local

重新運行spring-boot程序

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.3)

2021-03-04 10:22:05.930  INFO 31377 --- [           main] c.loyin.solar.SolarApplication   : Starting SolarApplication using Java 1.8.0_261 on lareinadeiMac.local with PID 31377 (/Users/liushengfeng/workspace/solar_monitor/solar_server_sb/target/classes started by liushengfeng in /Users/liushengfeng/workspace/solar_monitor/solar_server_sb)
2021-03-04 10:22:05.933  INFO 31377 --- [           main] c.loyin.solar.SolarApplication   : No active profile set, falling back to default profiles: default
2021-03-04 10:22:06.680  WARN 31377 --- [           main] io.undertow.websockets.jsr               : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2021-03-04 10:22:06.697  INFO 31377 --- [           main] io.undertow.servlet                      : Initializing Spring embedded WebApplicationContext
2021-03-04 10:22:06.700  INFO 31377 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 690 ms
2021-03-04 10:22:06.861  INFO 31377 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-04 10:22:06.997  INFO 31377 --- [           main] io.undertow                              : starting server: Undertow - 2.2.4.Final
2021-03-04 10:22:07.004  INFO 31377 --- [           main] org.xnio                                 : XNIO version 3.8.0.Final
2021-03-04 10:22:07.011  INFO 31377 --- [           main] org.xnio.nio                             : XNIO NIO Implementation Version 3.8.0.Final
2021-03-04 10:22:07.081  INFO 31377 --- [           main] org.jboss.threads                        : JBoss Threads version 3.1.0.Final
2021-03-04 10:22:07.138  INFO 31377 --- [           main] o.s.b.w.e.undertow.UndertowWebServer     : Undertow started on port(s) 8080 (http)
2021-03-04 10:22:07.148  INFO 31377 --- [           main] c.loyin.solar.SolarApplication   : Started SolarApplication in 1.58 seconds (JVM running for 1.887)

結果對比:

從啓動22秒到1.58秒

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章