天天看点

Spring Boot 1.5+ 使用JSP时,修改JSP不生效,需要重启的现象

  • 问题描述 

    公司项目用的Spring Boot,自己也就对他多研究一些,之前自己练习的Spring Boot项目,都是使用的JSP,在修改后直接刷新页面就可以看到效果,今天升级Spring Boot版本后,发现修改JSP后直接刷新页面没有用了。。。重启才能生效。。。

  • 问题定位 

    什么问题都抵不住爱折腾的心,我原以为更换了IDE(试了试IDEA这个工具)导致的,换回原来的Eclipse惊奇的发现也是无效的。 

    有想了想,觉得是不是因为修改POM文件添加了其他的jar包导致的(使用了shiro做权限,和redis做缓存),直接重新建一个Spring Boot项目,写了最简单的Controller,发现还是不行。。。哔了狗了。 

    各种尝试,想着难不成是Spring Boot版本升级导致的(从1.3.1升到了1.5.1)?换回1.3.1,擦!真的可以了

  • 问题原因 

    百度。。。木有答案,看来遇到的问题人还不多。。。 

    直接上stackoverflow,终于看到原因。在Spring Boot的GitHub上,有个大神(好吧,看来真的是很 牛 逼的大神)建议

spring-boot recompiles JSPs periodically leading to an unacceptable performance loss in production environments.
This behaviour is counter intuitive and hard to find.

The recompilation is behind a switch now but it's turned on (means it's in dev mode all the time).
I suggest to turn it off by default and enable it via the spring-boot-devtools.

The switch I am talking about is:

server.jsp-servlet.init-parameters.development           
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

大致是说:spring-boot对JSP的重新编译会导致不可接受性能降低在生产环境上。找出这个现象是啥啥啥并且艰难的。 。。。 

我建议默认关闭并且通过spring-boot-devtools来开启它(指JSP修改后立即重新编译) 。。。 

而这个开关我觉得可以是这样的: 

server.jsp-servlet.init-parameters.development

官方文档:

JSP servlet

The JSP servlet is no longer in development mode by default. 
Development mode is automatically enabled when using DevTools. 
It can also be enabled explicitly by 
setting server.jsp-servlet.init-parameters.development=true.           
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 解决方案 

    好吧,废话多了,解决方案如下 

    在配置文件application.properties中添加如下配置:

server.jsp-servlet.init-parameters.development=true           
  • 1

解决问题。

参考链接:http://blog.csdn.net/baidu_29092471/article/details/58596505

继续阅读