您现在的位置是:首页 >学无止境 >springboot-热部署网站首页学无止境
springboot-热部署
什么是热部署
事先我创建一个springboot项目,引入web依赖。
当我冷启动的时候,日志如下:
D: oolsjdk-17.0.3injava.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: oolsIDEAlibidea_rt.jar=6005:D: oolsIDEAin -Dfile.encoding=UTF-8 -classpath E:javaspringbootproject_coursehot-start argetclasses;D:
epositoryorgspringframeworkootspring-boot-devtools3.0.2spring-boot-devtools-3.0.2.jar;D:
epositoryorgspringframeworkootspring-boot3.0.2spring-boot-3.0.2.jar;D:
epositoryorgspringframeworkspring-context6.0.4spring-context-6.0.4.jar;D:
epositoryorgspringframeworkootspring-boot-autoconfigure3.0.2spring-boot-autoconfigure-3.0.2.jar;D:
epositoryorgspringframeworkootspring-boot-starter-web3.0.2spring-boot-starter-web-3.0.2.jar;D:
epositoryorgspringframeworkootspring-boot-starter3.0.2spring-boot-starter-3.0.2.jar;D:
epositoryorgspringframeworkootspring-boot-starter-logging3.0.2spring-boot-starter-logging-3.0.2.jar;D:
epositorychqoslogbacklogback-classic1.4.5logback-classic-1.4.5.jar;D:
epositorychqoslogbacklogback-core1.4.5logback-core-1.4.5.jar;D:
epositoryorgapachelogginglog4jlog4j-to-slf4j2.19.0log4j-to-slf4j-2.19.0.jar;D:
epositoryorgapachelogginglog4jlog4j-api2.19.0log4j-api-2.19.0.jar;D:
epositoryorgslf4jjul-to-slf4j2.0.6jul-to-slf4j-2.0.6.jar;D:
epositoryjakartaannotationjakarta.annotation-api2.1.1jakarta.annotation-api-2.1.1.jar;D:
epositoryorgyamlsnakeyaml1.33snakeyaml-1.33.jar;D:
epositoryorgspringframeworkootspring-boot-starter-json3.0.2spring-boot-starter-json-3.0.2.jar;D:
epositorycomfasterxmljacksoncorejackson-databind2.14.1jackson-databind-2.14.1.jar;D:
epositorycomfasterxmljacksoncorejackson-annotations2.14.1jackson-annotations-2.14.1.jar;D:
epositorycomfasterxmljacksoncorejackson-core2.14.1jackson-core-2.14.1.jar;D:
epositorycomfasterxmljacksondatatypejackson-datatype-jdk82.14.1jackson-datatype-jdk8-2.14.1.jar;D:
epositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.14.1jackson-datatype-jsr310-2.14.1.jar;D:
epositorycomfasterxmljacksonmodulejackson-module-parameter-names2.14.1jackson-module-parameter-names-2.14.1.jar;D:
epositoryorgspringframeworkootspring-boot-starter-tomcat3.0.2spring-boot-starter-tomcat-3.0.2.jar;D:
epositoryorgapache omcatembed omcat-embed-core10.1.5 omcat-embed-core-10.1.5.jar;D:
epositoryorgapache omcatembed omcat-embed-el10.1.5 omcat-embed-el-10.1.5.jar;D:
epositoryorgapache omcatembed omcat-embed-websocket10.1.5 omcat-embed-websocket-10.1.5.jar;D:
epositoryorgspringframeworkspring-web6.0.4spring-web-6.0.4.jar;D:
epositoryorgspringframeworkspring-beans6.0.4spring-beans-6.0.4.jar;D:
epositoryiomicrometermicrometer-observation1.10.3micrometer-observation-1.10.3.jar;D:
epositoryiomicrometermicrometer-commons1.10.3micrometer-commons-1.10.3.jar;D:
epositoryorgspringframeworkspring-webmvc6.0.4spring-webmvc-6.0.4.jar;D:
epositoryorgspringframeworkspring-aop6.0.4spring-aop-6.0.4.jar;D:
epositoryorgspringframeworkspring-expression6.0.4spring-expression-6.0.4.jar;D:
epositoryorgslf4jslf4j-api2.0.6slf4j-api-2.0.6.jar;D:
epositoryorgspringframeworkspring-core6.0.4spring-core-6.0.4.jar;D:
epositoryorgspringframeworkspring-jcl6.0.4spring-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:javaspringbootproject_coursehot-start argetclasses started by Administrator in E:javaspringbootproject_coursehot-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: oolsjdk-17.0.3injava.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: oolsIDEAlibidea_rt.jar=6005:D: oolsIDEAin -Dfile.encoding=UTF-8 -classpath E:javaspringbootproject_coursehot-start argetclasses;D:
epositoryorgspringframeworkootspring-boot-devtools3.0.2spring-boot-devtools-3.0.2.jar;D:
epositoryorgspringframeworkootspring-boot3.0.2spring-boot-3.0.2.jar;D:
epositoryorgspringframeworkspring-context6.0.4spring-context-6.0.4.jar;D:
epositoryorgspringframeworkootspring-boot-autoconfigure3.0.2spring-boot-autoconfigure-3.0.2.jar;D:
epositoryorgspringframeworkootspring-boot-starter-web3.0.2spring-boot-starter-web-3.0.2.jar;D:
epositoryorgspringframeworkootspring-boot-starter3.0.2spring-boot-starter-3.0.2.jar;D:
epositoryorgspringframeworkootspring-boot-starter-logging3.0.2spring-boot-starter-logging-3.0.2.jar;D:
epositorychqoslogbacklogback-classic1.4.5logback-classic-1.4.5.jar;D:
epositorychqoslogbacklogback-core1.4.5logback-core-1.4.5.jar;D:
epositoryorgapachelogginglog4jlog4j-to-slf4j2.19.0log4j-to-slf4j-2.19.0.jar;D:
epositoryorgapachelogginglog4jlog4j-api2.19.0log4j-api-2.19.0.jar;D:
epositoryorgslf4jjul-to-slf4j2.0.6jul-to-slf4j-2.0.6.jar;D:
epositoryjakartaannotationjakarta.annotation-api2.1.1jakarta.annotation-api-2.1.1.jar;D:
epositoryorgyamlsnakeyaml1.33snakeyaml-1.33.jar;D:
epositoryorgspringframeworkootspring-boot-starter-json3.0.2spring-boot-starter-json-3.0.2.jar;D:
epositorycomfasterxmljacksoncorejackson-databind2.14.1jackson-databind-2.14.1.jar;D:
epositorycomfasterxmljacksoncorejackson-annotations2.14.1jackson-annotations-2.14.1.jar;D:
epositorycomfasterxmljacksoncorejackson-core2.14.1jackson-core-2.14.1.jar;D:
epositorycomfasterxmljacksondatatypejackson-datatype-jdk82.14.1jackson-datatype-jdk8-2.14.1.jar;D:
epositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.14.1jackson-datatype-jsr310-2.14.1.jar;D:
epositorycomfasterxmljacksonmodulejackson-module-parameter-names2.14.1jackson-module-parameter-names-2.14.1.jar;D:
epositoryorgspringframeworkootspring-boot-starter-tomcat3.0.2spring-boot-starter-tomcat-3.0.2.jar;D:
epositoryorgapache omcatembed omcat-embed-core10.1.5 omcat-embed-core-10.1.5.jar;D:
epositoryorgapache omcatembed omcat-embed-el10.1.5 omcat-embed-el-10.1.5.jar;D:
epositoryorgapache omcatembed omcat-embed-websocket10.1.5 omcat-embed-websocket-10.1.5.jar;D:
epositoryorgspringframeworkspring-web6.0.4spring-web-6.0.4.jar;D:
epositoryorgspringframeworkspring-beans6.0.4spring-beans-6.0.4.jar;D:
epositoryiomicrometermicrometer-observation1.10.3micrometer-observation-1.10.3.jar;D:
epositoryiomicrometermicrometer-commons1.10.3micrometer-commons-1.10.3.jar;D:
epositoryorgspringframeworkspring-webmvc6.0.4spring-webmvc-6.0.4.jar;D:
epositoryorgspringframeworkspring-aop6.0.4spring-aop-6.0.4.jar;D:
epositoryorgspringframeworkspring-expression6.0.4spring-expression-6.0.4.jar;D:
epositoryorgslf4jslf4j-api2.0.6slf4j-api-2.0.6.jar;D:
epositoryorgspringframeworkspring-core6.0.4spring-core-6.0.4.jar;D:
epositoryorgspringframeworkspring-jcl6.0.4spring-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:javaspringbootproject_coursehot-start argetclasses started by Administrator in E:javaspringbootproject_coursehot-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:javaspringbootproject_coursehot-start argetclasses started by Administrator in E:javaspringbootproject_coursehot-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:javaspringbootproject_coursehot-start argetclasses started by Administrator in E:javaspringbootproject_coursehot-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);
}
}