什么是热部署
事先我创建一个springboot项目,引入web依赖。
当我冷启动的时候,日志如下:
D:\tools\jdk-17.0.3\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:D:\tools\IDEA\lib\idea_rt.jar=6005:D:\tools\IDEA\bin -Dfile.encoding=UTF-8 -classpath E:\java\springboot\project_course\hot-start\target\classes;D:\repository\org\springframework\boot\spring-boot-devtools\3.0.2\spring-boot-devtools-3.0.2.jar;D:\repository\org\springframework\boot\spring-boot\3.0.2\spring-boot-3.0.2.jar;D:\repository\org\springframework\spring-context\6.0.4\spring-context-6.0.4.jar;D:\repository\org\springframework\boot\spring-boot-autoconfigure\3.0.2\spring-boot-autoconfigure-3.0.2.jar;D:\repository\org\springframework\boot\spring-boot-starter-web\3.0.2\spring-boot-starter-web-3.0.2.jar;D:\repository\org\springframework\boot\spring-boot-starter\3.0.2\spring-boot-starter-3.0.2.jar;D:\repository\org\springframework\boot\spring-boot-starter-logging\3.0.2\spring-boot-starter-logging-3.0.2.jar;D:\repository\ch\qos\logback\logback-classic\1.4.5\logback-classic-1.4.5.jar;D:\repository\ch\qos\logback\logback-core\1.4.5\logback-core-1.4.5.jar;D:\repository\org\apache\logging\log4j\log4j-to-slf4j\2.19.0\log4j-to-slf4j-2.19.0.jar;D:\repository\org\apache\logging\log4j\log4j-api\2.19.0\log4j-api-2.19.0.jar;D:\repository\org\slf4j\jul-to-slf4j\2.0.6\jul-to-slf4j-2.0.6.jar;D:\repository\jakarta\annotation\jakarta.annotation-api\2.1.1\jakarta.annotation-api-2.1.1.jar;D:\repository\org\yaml\snakeyaml\1.33\snakeyaml-1.33.jar;D:\repository\org\springframework\boot\spring-boot-starter-json\3.0.2\spring-boot-starter-json-3.0.2.jar;D:\repository\com\fasterxml\jackson\core\jackson-databind\2.14.1\jackson-databind-2.14.1.jar;D:\repository\com\fasterxml\jackson\core\jackson-annotations\2.14.1\jackson-annotations-2.14.1.jar;D:\repository\com\fasterxml\jackson\core\jackson-core\2.14.1\jackson-core-2.14.1.jar;D:\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.14.1\jackson-datatype-jdk8-2.14.1.jar;D:\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.14.1\jackson-datatype-jsr310-2.14.1.jar;D:\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.14.1\jackson-module-parameter-names-2.14.1.jar;D:\repository\org\springframework\boot\spring-boot-starter-tomcat\3.0.2\spring-boot-starter-tomcat-3.0.2.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-core\10.1.5\tomcat-embed-core-10.1.5.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-el\10.1.5\tomcat-embed-el-10.1.5.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-websocket\10.1.5\tomcat-embed-websocket-10.1.5.jar;D:\repository\org\springframework\spring-web\6.0.4\spring-web-6.0.4.jar;D:\repository\org\springframework\spring-beans\6.0.4\spring-beans-6.0.4.jar;D:\repository\io\micrometer\micrometer-observation\1.10.3\micrometer-observation-1.10.3.jar;D:\repository\io\micrometer\micrometer-commons\1.10.3\micrometer-commons-1.10.3.jar;D:\repository\org\springframework\spring-webmvc\6.0.4\spring-webmvc-6.0.4.jar;D:\repository\org\springframework\spring-aop\6.0.4\spring-aop-6.0.4.jar;D:\repository\org\springframework\spring-expression\6.0.4\spring-expression-6.0.4.jar;D:\repository\org\slf4j\slf4j-api\2.0.6\slf4j-api-2.0.6.jar;D:\repository\org\springframework\spring-core\6.0.4\spring-core-6.0.4.jar;D:\repository\org\springframework\spring-jcl\6.0.4\spring-jcl-6.0.4.jar cn.oesoft.hotstart.HotStartApplication
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.2)
2023-05-11T15:40:21.186+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : Starting HotStartApplication using Java 17.0.3 with PID 18892 (E:\java\springboot\project_course\hot-start\target\classes started by Administrator in E:\java\springboot\project_course\hot-start)
2023-05-11T15:40:21.186+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : No active profile set, falling back to 1 default profile: "default"
2023-05-11T15:40:21.273+08:00 INFO 18892 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-05-11T15:40:21.273+08:00 INFO 18892 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-05-11T15:40:22.545+08:00 INFO 18892 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-05-11T15:40:22.545+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : An older version [1.2.36] of the Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of [2.0.1]
2023-05-11T15:40:22.545+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : Loaded Apache Tomcat Native library [1.2.36] using APR version [1.7.2].
2023-05-11T15:40:22.545+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.1t 7 Feb 2023]
2023-05-11T15:40:22.561+08:00 INFO 18892 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-05-11T15:40:22.561+08:00 INFO 18892 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.5]
2023-05-11T15:40:22.639+08:00 INFO 18892 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-05-11T15:40:22.639+08:00 INFO 18892 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1366 ms
2023-05-11T15:40:22.890+08:00 INFO 18892 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2023-05-11T15:40:23.015+08:00 INFO 18892 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2023-05-11T15:40:23.078+08:00 INFO 18892 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-05-11T15:40:23.094+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : Started HotStartApplication in 2.455 seconds (process running for 3.9)
ccc
当我修改了两个Java类,一个是启动类,使它输出aaa,不再是ccc,一个是controller类,热部署的日志如下:
D:\tools\jdk-17.0.3\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:D:\tools\IDEA\lib\idea_rt.jar=6005:D:\tools\IDEA\bin -Dfile.encoding=UTF-8 -classpath E:\java\springboot\project_course\hot-start\target\classes;D:\repository\org\springframework\boot\spring-boot-devtools\3.0.2\spring-boot-devtools-3.0.2.jar;D:\repository\org\springframework\boot\spring-boot\3.0.2\spring-boot-3.0.2.jar;D:\repository\org\springframework\spring-context\6.0.4\spring-context-6.0.4.jar;D:\repository\org\springframework\boot\spring-boot-autoconfigure\3.0.2\spring-boot-autoconfigure-3.0.2.jar;D:\repository\org\springframework\boot\spring-boot-starter-web\3.0.2\spring-boot-starter-web-3.0.2.jar;D:\repository\org\springframework\boot\spring-boot-starter\3.0.2\spring-boot-starter-3.0.2.jar;D:\repository\org\springframework\boot\spring-boot-starter-logging\3.0.2\spring-boot-starter-logging-3.0.2.jar;D:\repository\ch\qos\logback\logback-classic\1.4.5\logback-classic-1.4.5.jar;D:\repository\ch\qos\logback\logback-core\1.4.5\logback-core-1.4.5.jar;D:\repository\org\apache\logging\log4j\log4j-to-slf4j\2.19.0\log4j-to-slf4j-2.19.0.jar;D:\repository\org\apache\logging\log4j\log4j-api\2.19.0\log4j-api-2.19.0.jar;D:\repository\org\slf4j\jul-to-slf4j\2.0.6\jul-to-slf4j-2.0.6.jar;D:\repository\jakarta\annotation\jakarta.annotation-api\2.1.1\jakarta.annotation-api-2.1.1.jar;D:\repository\org\yaml\snakeyaml\1.33\snakeyaml-1.33.jar;D:\repository\org\springframework\boot\spring-boot-starter-json\3.0.2\spring-boot-starter-json-3.0.2.jar;D:\repository\com\fasterxml\jackson\core\jackson-databind\2.14.1\jackson-databind-2.14.1.jar;D:\repository\com\fasterxml\jackson\core\jackson-annotations\2.14.1\jackson-annotations-2.14.1.jar;D:\repository\com\fasterxml\jackson\core\jackson-core\2.14.1\jackson-core-2.14.1.jar;D:\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.14.1\jackson-datatype-jdk8-2.14.1.jar;D:\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.14.1\jackson-datatype-jsr310-2.14.1.jar;D:\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.14.1\jackson-module-parameter-names-2.14.1.jar;D:\repository\org\springframework\boot\spring-boot-starter-tomcat\3.0.2\spring-boot-starter-tomcat-3.0.2.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-core\10.1.5\tomcat-embed-core-10.1.5.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-el\10.1.5\tomcat-embed-el-10.1.5.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-websocket\10.1.5\tomcat-embed-websocket-10.1.5.jar;D:\repository\org\springframework\spring-web\6.0.4\spring-web-6.0.4.jar;D:\repository\org\springframework\spring-beans\6.0.4\spring-beans-6.0.4.jar;D:\repository\io\micrometer\micrometer-observation\1.10.3\micrometer-observation-1.10.3.jar;D:\repository\io\micrometer\micrometer-commons\1.10.3\micrometer-commons-1.10.3.jar;D:\repository\org\springframework\spring-webmvc\6.0.4\spring-webmvc-6.0.4.jar;D:\repository\org\springframework\spring-aop\6.0.4\spring-aop-6.0.4.jar;D:\repository\org\springframework\spring-expression\6.0.4\spring-expression-6.0.4.jar;D:\repository\org\slf4j\slf4j-api\2.0.6\slf4j-api-2.0.6.jar;D:\repository\org\springframework\spring-core\6.0.4\spring-core-6.0.4.jar;D:\repository\org\springframework\spring-jcl\6.0.4\spring-jcl-6.0.4.jar cn.oesoft.hotstart.HotStartApplication
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.2)
2023-05-11T15:40:21.186+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : Starting HotStartApplication using Java 17.0.3 with PID 18892 (E:\java\springboot\project_course\hot-start\target\classes started by Administrator in E:\java\springboot\project_course\hot-start)
2023-05-11T15:40:21.186+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : No active profile set, falling back to 1 default profile: "default"
2023-05-11T15:40:21.273+08:00 INFO 18892 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-05-11T15:40:21.273+08:00 INFO 18892 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-05-11T15:40:22.545+08:00 INFO 18892 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-05-11T15:40:22.545+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : An older version [1.2.36] of the Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of [2.0.1]
2023-05-11T15:40:22.545+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : Loaded Apache Tomcat Native library [1.2.36] using APR version [1.7.2].
2023-05-11T15:40:22.545+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.1t 7 Feb 2023]
2023-05-11T15:40:22.561+08:00 INFO 18892 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-05-11T15:40:22.561+08:00 INFO 18892 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.5]
2023-05-11T15:40:22.639+08:00 INFO 18892 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-05-11T15:40:22.639+08:00 INFO 18892 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1366 ms
2023-05-11T15:40:22.890+08:00 INFO 18892 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2023-05-11T15:40:23.015+08:00 INFO 18892 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2023-05-11T15:40:23.078+08:00 INFO 18892 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-05-11T15:40:23.094+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : Started HotStartApplication in 2.455 seconds (process running for 3.9)
ccc
2023-05-11T15:53:21.057+08:00 INFO 18892 --- [ File Watcher] rtingClassPathChangeChangedEventListener : Restarting due to 2 class path changes (0 additions, 2 deletions, 0 modifications)
2023-05-11T15:53:21.135+08:00 INFO 18892 --- [ Thread-5] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.2)
2023-05-11T15:53:21.259+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : Starting HotStartApplication using Java 17.0.3 with PID 18892 (E:\java\springboot\project_course\hot-start\target\classes started by Administrator in E:\java\springboot\project_course\hot-start)
2023-05-11T15:53:21.259+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : No active profile set, falling back to 1 default profile: "default"
2023-05-11T15:53:21.615+08:00 INFO 18892 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-05-11T15:53:21.615+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : An older version [1.2.36] of the Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of [2.0.1]
2023-05-11T15:53:21.615+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : Loaded Apache Tomcat Native library [1.2.36] using APR version [1.7.2].
2023-05-11T15:53:21.615+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.1t 7 Feb 2023]
2023-05-11T15:53:21.615+08:00 INFO 18892 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-05-11T15:53:21.615+08:00 INFO 18892 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.5]
2023-05-11T15:53:21.633+08:00 INFO 18892 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-05-11T15:53:21.633+08:00 INFO 18892 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 374 ms
2023-05-11T15:53:21.725+08:00 INFO 18892 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2023-05-11T15:53:21.788+08:00 INFO 18892 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2023-05-11T15:53:21.804+08:00 INFO 18892 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-05-11T15:53:21.819+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : Started HotStartApplication in 0.612 seconds (process running for 782.628)
2023-05-11T15:53:21.819+08:00 INFO 18892 --- [ restartedMain] .ConditionEvaluationDeltaLoggingListener : Condition evaluation unchanged
ccc
2023-05-11T15:53:24.225+08:00 INFO 18892 --- [ File Watcher] rtingClassPathChangeChangedEventListener : Restarting due to 2 class path changes (2 additions, 0 deletions, 0 modifications)
2023-05-11T15:53:24.272+08:00 INFO 18892 --- [ Thread-7] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.2)
2023-05-11T15:53:24.366+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : Starting HotStartApplication using Java 17.0.3 with PID 18892 (E:\java\springboot\project_course\hot-start\target\classes started by Administrator in E:\java\springboot\project_course\hot-start)
2023-05-11T15:53:24.366+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : No active profile set, falling back to 1 default profile: "default"
2023-05-11T15:53:24.660+08:00 INFO 18892 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-05-11T15:53:24.660+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : An older version [1.2.36] of the Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of [2.0.1]
2023-05-11T15:53:24.660+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : Loaded Apache Tomcat Native library [1.2.36] using APR version [1.7.2].
2023-05-11T15:53:24.660+08:00 INFO 18892 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.1t 7 Feb 2023]
2023-05-11T15:53:24.660+08:00 INFO 18892 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-05-11T15:53:24.660+08:00 INFO 18892 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.5]
2023-05-11T15:53:24.676+08:00 INFO 18892 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-05-11T15:53:24.676+08:00 INFO 18892 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 294 ms
2023-05-11T15:53:24.740+08:00 INFO 18892 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2023-05-11T15:53:24.785+08:00 INFO 18892 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2023-05-11T15:53:24.801+08:00 INFO 18892 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-05-11T15:53:24.801+08:00 INFO 18892 --- [ restartedMain] cn.oesoft.hotstart.HotStartApplication : Started HotStartApplication in 0.465 seconds (process running for 785.615)
2023-05-11T15:53:24.801+08:00 INFO 18892 --- [ restartedMain] .ConditionEvaluationDeltaLoggingListener : Condition evaluation unchanged
aaa
分析如下:
热部署始终使用同一个进程,冷启动创建一个新的进程。在热部署例子中,修改了两个类,但类路径上是先删除后增加两个字节码文件,导致两次热部署,但明显用时比冷启动要短。在类路径上删除启动类字节码后,热部署时不会删除它,要是删除它,应用就运行不了,但删除controller类字节码后,热部署时spring容器就会删除它,导致某段时间访问时,出现404。
结论:
热部署就是重启:自定义开发代码,包括类、页面、配置文件等,加载位置是restart类加载器。
冷启动的话还包括重载:jar包,加载位置是base类加载器。
如何实现热部署
springboot使用内嵌的Tomcat,Tomcat也是spring容器的一个对象,那么这个对象如何知道自定义代码发生了变化?需要有个工具帮助它,如下:
在pom文件中添加spring-boot-devtools热部署依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
手动热部署:
build-》build project,激活热部署
自动热部署:
设置自动构建
eclipse:
idea:
IDEA配置热部署_idea热部署配置_微风粼粼的博客-CSDN博客
1、file-》settings-》build..-》compiler->build project automatically
2、ctrl+Alt+shift+/ ->registry...->选中compiler.automake.allow.when.app.running(如果存在)
激活方式:焦点离开idea 5秒后 重启
热部署测试
修改HelloController的方法的返回值
热部署配置范围
默认不触发重启的目录列表
/META-INF/maven
/META-INF/resources
/resources
/static
/public
/templates
设置不触发重启的项
spring.devtools.restart.exclude=config/application.properties,static/**
禁用热部署
spring.devtools.restart.enabled=false
由于其他人也会通过配置启用热部署,导致自己的配置失效,那么我们可以在更高一层配置。
我们可以通过第六级完成更高一层的配置
@SpringBootApplication
public class HotStartApplication {
public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled","false");
SpringApplication.run(HotStartApplication.class, args);
}
}