spring boot项目中使用spring-boot-devtools模块进行代码热部署,避免重新启动web项目
来源:互联网 发布:淘宝赚差价采集软件 编辑:程序博客网 时间:2024/06/05 11:09
devtools模块,是为开发者服务的一个模块。主要的功能就是代码修改后一般在5秒之内就会自动重新加载至服务器,相当于restart成功。
spring-boot提供的重新启动技术使用两个类加载器,一个类加载器用来加载那些不变的类(如第三方jar包提供的类),另外一个用来加载正在开发的代码类,你正在开发的类被加载进了一个重新启动类加载器中,当应用程序 重新启动时会抛弃掉之前的类加载器,然后重新创建一个重新启动的类加载器,所以使用DevTools工具模块重新部署代码是很快的。
只要我们修改了classpath下任何文件只要保存Devtools模块都会重新启动应用程序。
一、spring-boot-devtools模块是一个为开发者服务的模块,其中最重要的功能就是代码的热部署,只需在pom文件中加入如下依赖不需要任何其他的配置
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional></dependency></dependencies>
二、加入如上的代码依赖我们使用启动web项目,然后修改一下代码可以看到后台重新编译运行了项目,而且结果也改变了
2017-10-15 17:14:58.619 INFO 1519 --- [ Thread-6] ConfigServletWebServerApplicationContext : Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@895709: startup date [Sun Oct 15 17:14:20 CST 2017]; root of context hierarchy2017-10-15 17:14:58.624 WARN 1519 --- [ Thread-6] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'classPathFileSystemWatcher': java.lang.NullPointerException2017-10-15 17:14:58.625 INFO 1519 --- [ Thread-6] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.0.BUILD-SNAPSHOT)2017-10-15 17:14:58.876 INFO 1519 --- [ restartedMain] ggauthority.v1.GgauthorityApplication : Starting GgauthorityApplication on yaomingyangdeMacBook-Pro.local with PID 1519 (/Users/yaomingyang/Documents/IDE/workplace/ggauthority/target/classes started by yaomingyang in /Users/yaomingyang/Documents/IDE/workplace/ggauthority)2017-10-15 17:14:58.877 INFO 1519 --- [ restartedMain] ggauthority.v1.GgauthorityApplication : No active profile set, falling back to default profiles: default2017-10-15 17:14:58.880 INFO 1519 --- [ restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2fc9f5: startup date [Sun Oct 15 17:14:58 CST 2017]; root of context hierarchy2017-10-15 17:14:59.401 INFO 1519 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8011 (http)2017-10-15 17:14:59.402 INFO 1519 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]2017-10-15 17:14:59.403 INFO 1519 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.232017-10-15 17:14:59.409 INFO 1519 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext2017-10-15 17:14:59.410 INFO 1519 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 530 ms2017-10-15 17:14:59.446 INFO 1519 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]2017-10-15 17:14:59.447 INFO 1519 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]2017-10-15 17:14:59.447 INFO 1519 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]2017-10-15 17:14:59.447 INFO 1519 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]2017-10-15 17:14:59.447 INFO 1519 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]2017-10-15 17:14:59.480 INFO 1519 --- [ restartedMain] org.mongodb.driver.cluster : Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}2017-10-15 17:14:59.547 INFO 1519 --- [127.0.0.1:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:19}] to 127.0.0.1:270172017-10-15 17:14:59.548 INFO 1519 --- [127.0.0.1:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=127.0.0.1:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 11]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, roundTripTimeNanos=635614}2017-10-15 17:14:59.678 INFO 1519 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2fc9f5: startup date [Sun Oct 15 17:14:58 CST 2017]; root of context hierarchy2017-10-15 17:14:59.691 INFO 1519 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/users/list],methods=[GET || POST]}" onto public ggauthority.v1.user.entity.User ggauthority.v1.user.controller.UserController.list(java.lang.Long)2017-10-15 17:14:59.691 INFO 1519 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/users/get_user/{user_id}],methods=[GET || POST]}" onto public java.util.Map<java.lang.String, java.lang.Object> ggauthority.v1.user.controller.UserController.get_user(java.lang.Long)2017-10-15 17:14:59.696 INFO 1519 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)2017-10-15 17:14:59.696 INFO 1519 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)2017-10-15 17:14:59.708 INFO 1519 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]2017-10-15 17:14:59.709 INFO 1519 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]2017-10-15 17:14:59.727 INFO 1519 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]2017-10-15 17:14:59.776 INFO 1519 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 357292017-10-15 17:14:59.883 INFO 1519 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup2017-10-15 17:14:59.904 INFO 1519 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8011 (http)2017-10-15 17:14:59.907 INFO 1519 --- [ restartedMain] ggauthority.v1.GgauthorityApplication : Started GgauthorityApplication in 1.07 seconds (JVM running for 40.767)
三、当你更改不在classpath下的文件你可能想让你的应用程序重新启动或者只加载对应的文件,你可以使用spring.devtools.restart.additional-paths属性配置文件将对应的文件加载到devtools工具的检测范围之内,spring.devtools.restart.exclude排除那个目录下不需要加载。
#添加那个目录的文件需要restartspring.devtools.restart.additional-paths=src/main/java#排除那个目录的文件不需要restartspring.devtools.restart.exclude=static/**,public/**
四、可以通过设置spring.devtools.restart.enabled=false禁用devtools模块的功能。
阅读全文
0 0
- spring boot项目中使用spring-boot-devtools模块进行代码热部署,避免重新启动web项目
- maven工程使用spring-boot-devtools进行热部署,更改代码避免重启web容器
- SpringBoot学习:使用spring-boot-devtools进行热部署
- SpringBoot:使用spring-boot-devtools进行热部署
- SpringBoot学习:使用spring-boot-devtools进行热部署
- Spring Boot热部署spring-boot-devtools
- spring boot 热部署 devtools
- spring-boot-devtools热部署
- spring boot项目热部署
- Spring Boot 菜鸟教程 5 热部署 devtools模块
- Spring Boot热部署—SpringBoot + Devtools
- 6.Spring Boot热部署之devtools
- idea+spring-boot+devtools热部署
- idea + spring-boot-devtools启动热部署
- Spring Boot 之devtools热部署
- spring boot devtools 热部署工具
- spring-boot-devtools热部署实现
- Spring Boot-配置devtools实现热部署
- linux安装opencv
- Java知识---抽象类
- bootstrap-table的使用
- 瞬时极性法判断反馈类型
- hdoj 5583 Kingdom of Black and White
- spring boot项目中使用spring-boot-devtools模块进行代码热部署,避免重新启动web项目
- DS18B20温度传感器在90c51上的使用
- 设计模式--适配器模式
- 内部类二
- 字符串的其它注意事项--cookbook读书笔记
- 是否接种狂犬疫苗
- Knn算法(约会问题应用)
- 高数 01.01 函数
- 那些年,带我们走上数据分析之路的Excel——致敬