0
点赞
收藏
分享

微信扫一扫

Spring Boot开启JSP页面热部署和开启全局热部署


一、开启jsp页面热部署

1.1 引言

​在springboot中默认对jsp运行为生产模式,不允许修改内容保存后立即生效,因此在开发过程需要调试jsp页面每次需要重新启动服务器这样极大影响了我们的效率,为此springboot中提供了可以将默认的生产模式修改为调试模式,改为调试模式后就可以保存立即生效,如何配置为测试模式需要在配置文件中加入如下配置即可修改为开发模式。​

1.2 配置开启测试模式

#老版本的Spring Boot

server:
port: 8989
jsp-servlet:
init-parameters:
development: true #开启jsp页面的调试模式

#新版本的Spring Boot

server:
port: 8081
servlet:
jsp:
init-parameters:
development: true

 

二、springboot中devtools热部署

2.1 引言

​为了进一步提高开发效率,springboot为我们提供了全局项目热部署,日后在开发过程中修改了部分代码以及相关配置文件后,不需要每次重启使修改生效,在项目中开启了springboot全局热部署之后只需要在修改之后等待几秒即可使修改生效。​

2.2 开启热部署

2.2.1 项目中引入依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

2.2.2 设置idea中支持自动编译

# 1.开启自动编译

Preferences | Build, Execution, Deployment | Compiler -> 勾选上 Build project automatically 这个选项

# 2.开启允许在运行过程中修改文件
ctrl + alt + shift + / ---->选择1.Registry ---> 勾选 compiler.automake.allow.when.app.running 这个选项

2.2.3 启动项目检测热部署是否生效

# 1.启动出现如下日志代表生效

2019-07-17 21:23:17.566 INFO 4496 --- [ restartedMain] com.baizhi.InitApplication : Starting InitApplication on chenyannandeMacBook-Pro.local with PID 4496 (/Users/chenyannan/IdeaProjects/ideacode/springboot_day1/target/classes started by chenyannan in /Users/chenyannan/IdeaProjects/ideacode/springboot_day1)
2019-07-17 21:23:17.567 INFO 4496 --- [ restartedMain] com.baizhi.InitApplication : The following profiles are active: dev
2019-07-17 21:23:17.612 INFO 4496 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@66d799c5: startup date [Wed Jul 17 21:23:17 CST 2019]; root of context hierarchy
2019-07-17 21:23:18.782 INFO 4496 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8989 (http)
2019-07-17 21:23:18.796 INFO 4496 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-07-17 21:23:18.797 INFO 4496 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.20

​注意:​

​日志出现restartedMain代表已经生效,在使用热部署时如果遇到修改之后不能生效,请重试重启项目在试​

全局热部署不是很稳定,用的次数多了会造成有的代码部署不上,需要手动启动项目才行,而且和 redis 反序列化有冲突,和通用 Mapper 有冲突,和 Shiro 的缓存有冲突,好的,可以放弃了。

注意:devtools热部署使用后  idea 中项目就无法 debug 了。还有与缓存相关的东西都会有冲突,包括 redis 缓存,shiro 缓存,都需要额外的配置。

注意:配置devtools热部署时, <fork>属性可以不添加,但是如果添加了值一定 为 true 热部署才会生效,同时 debug 功能失效

<configuration> <!--该属性为 true 时无法使用 debug --> <fork>true</fork> <!-- spring-boot:run 中文乱码解决 --> <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments> </configuration>

 

 

举报

相关推荐

0 条评论