为什么JSP重新编译需要一定的时间间隔?

mmvthczy  于 2024-01-04  发布在  其他
关注(0)|答案(2)|浏览(320)

我在M1 Mac上的spring Boot 3.2.0中使用JSP(请不要提到Thymeleaf.),我发现如果我连续更新同一个JSP文件,重新编译不会立即发生,浏览器中显示的页面也不会更新。如果我等待,比如说,5秒,就会发生。
所以,我是说,

  1. When I update a JSP file and immediately access it:
  2. (The page is recompiled and updated, then I wait a few seconds)
  3. Update JSP, immediate access again
  4. (The page is recompiled and updated)

字符串
但是,如果我不做任何间隔:

  1. Update JSP, immediate access
  2. (The page is recompiled and updated, and then immediately again)
  3. Update JSP, immediate access
  4. (The recompilation does not happen and the page is not updated...)


就是这样
有什么设置可以解决这个问题吗?
以下是视图index.jsp

  1. <!DOCTYPE html>
  2. <html>
  3. <head></head>
  4. <body>
  5. hello world
  6. </body>
  7. </html>


控制器:

  1. package com.example.mysite.controller;
  2. import org.springframework.stereotype.Controller;
  3. import org.springframework.web.bind.annotation.GetMapping;
  4. @Controller
  5. public class RootController {
  6. @GetMapping
  7. public String index() {
  8. return "index";
  9. }
  10. }


application.properties

  1. spring.mvc.view.prefix=/WEB-INF/jsp/
  2. spring.mvc.view.suffix=.jsp
  3. # These don't work
  4. # server.jsp-servlet.init-parameters.modificationTestInterval=0
  5. # server.jsp-servlet.init-parameters.development=true

编辑

这里有更多的细节和信息。
我尝试创建一个最小情况。下面是代码及其行为(请参阅附带的behavior视频):https://fastupload.io/grsd2af5JAQE9ql/file
从从IntelliJ创建一个spring Boot 项目开始,

  • pom.xml
  • application.properties
  • RootController.java
  • index.jsp

是唯一更新的文件
我注意到,在视频中,即使是第一次编辑也没有立即显示在浏览器上..

c7rzv4ha

c7rzv4ha1#

您指出以下属性在您的情况下不起作用

  1. # These don't work
  2. # server.jsp-servlet.init-parameters.modificationTestInterval=0
  3. # server.jsp-servlet.init-parameters.development=true

字符串
根据当前(so 3.2)文档,init-parameters的属性前缀是server.servlet.jsp.init-parameters.*
所以你应该试着

  1. server.servlet.jsp.init-parameters.development=true
  2. server.servlet.jsp.init-parameters.modificationTestInterval=0


Tomcat的documentation属性集的提取:

  • 发展 *

碧玉是否用于开发模式?如果为true,则可以通过modificationTestInterval参数指定检查JSP修改的频率。true或false,默认值为true。
在SpringBoot中,默认情况下,此属性被重写为false(参见org.springframework.boot.web.servlet.server.Jsp.Jsp()构造函数,其中他们将development的init-parameter添加到false

  • modificationTestInterval*

使JSP(及其依赖文件)在指定的时间间隔(以秒为单位)内(从上次检查JSP是否修改开始)不进行修改检查。值为0将使每次访问时检查JSP。仅在开发模式下使用。默认值为4秒。
如果您已经有了springboot-devtools,server.servlet.jsp.init-parameters.development参数已经设置为true,以避免处理开发模式和生产模式配置属性(参考此处)
您还应该检查排除资源文档,以免在更改JSP文件时触发spring-boot devtools的完全重启
默认情况下,更改/META-INF/maven、/META-INF/resources、/resources、/static、/public或/templates中的资源不会触发重新启动,但会触发实时重新加载。

EDIT通过添加以下属性,您还可以在Tomcat中禁用内部缓存,并且您的JSP应该始终保持最新:

  1. server.tomcat.resource.allow-caching=false

展开查看全部
wz8daaqr

wz8daaqr2#

有一个属性可以在Tomcat服务器的嵌入式示例上配置JSPServlet,该属性默认情况下在spring-boot中使用spring-boot-starter-web依赖项。
modificationTestInterval属性默认设置为4秒。这是等待JSP下一次修改的时间。
请参阅官方的Tomcat文档Jasper 2 JSP Engine How To。需要两个参数:

  • modificationTestInterval-导致在指定的时间间隔(以秒为单位)内不检查JSP(及其依赖文件)的修改,该时间间隔是从上次检查JSP的修改开始算起的。值为0将导致每次访问时都检查JSP。仅在开发模式下使用。默认值为4秒。
  • development-碧玉是否用于开发模式?如果是true,检查JSP是否修改的频率可以通过modificationTestInterval参数指定。truefalse,默认值为true

因此,您可以按如下方式更改嵌入式Tomcat的默认配置

  1. server.jsp-servlet.init-parameters.modificationTestInterval=0

字符串
您应该在Sping Boot 中检查Tomcat是否默认以developer模式运行。
如果您正在寻找在Sping Boot 中修改嵌入式Tomcat选项的方法,请参阅SpringBoot Embedded Tomcat JSPServlet Options
你可以只添加参数到你的application.properties文件所描述的here
寻找:

  1. server.jsp-servlet.init-parameters.*= # Init parameters used to configure the JSP servlet

展开查看全部

相关问题