spring boot + JSP - JSP重新编译需要一些间隔?

问题描述 投票:0回答:1

我在 Spring Boot 中使用 JSP(请不要提及 Thymeleaf...),我发现如果我连续更新相同的 JSP 文件,则不会发生重新编译,浏览器中的页面也不会更新。如果我等待,比如说 5 秒,它就会发生。

所以,我的意思是,

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

但是,如果我没有任何间隔地进行:

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

...就是发生的事情。

有什么设置可以解决这个问题吗?

供您参考,这是 JSP 文件:

<!DOCTYPE html>
<html>
<head></head>
<body>
hello world
</body>
</html>

控制器:

package com.example.mysite.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class RootController {
  @GetMapping
  public String index() {
    return "index";
  }
}

application.properties

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/mysite
spring.datasource.username=postgres
spring.datasource.password=password
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
java spring spring-boot spring-mvc jsp
1个回答
0
投票

有一个属性可以在 Tomcat 服务器的嵌入式实例上配置

JSPServlet
,默认情况下使用
spring-boot
依赖项在
spring-starter-web
中使用该属性。

modificationTestInterval
属性默认设置为 4 秒。这是等待 JSP 下一次修改发生的时间。

请参阅官方 Tomcat 文档 Jasper 2 JSP 引擎操作方法。需要两个参数:

  • modificationTestInterval
    - 导致在上次检查 JSP 修改后的指定时间间隔(以秒为单位)内不检查 JSP(及其相关文件)的修改情况。 值 0 将导致每次访问时都检查 JSP 。仅在开发模式下使用。默认为 4 秒。
  • development
    - Jasper 是否用于开发模式?如果
    true
    ,则可以通过修改测试间隔参数指定检查 JSP 修改的频率。
    true
    false
    ,默认
    true

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

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

您应该检查 Spring Boot 中 Tomcat 是否默认以

developer
模式运行。

如果您正在寻找修改 Spring Boot 中嵌入式 Tomcat 选项的方法,请参阅 SpringBoot 嵌入式 Tomcat JSPServlet 选项

您可以按照

此处
的说明将参数添加到您的application.properties

文件中

寻找:

server.jsp-servlet.init-parameters.*= # Init parameters used to configure the JSP servlet
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.