传统支持JSP的复杂单体应用升级到Spring Boot 重点注意事项

1.传统项目都是有各种配置的,不要@EnableAutoConfiguration。开启之后各种冲突,后患无穷。
思维:Spring Boot的自动配置与传统配置,一个是自动一个是人为控制。离得目标近,圆上两点距离。
策略:不要@EnableAutoConfiguration,报什么错误解决什么错误。人为控制,更易于达到升级的短期目标,长期目标当然是微服务。

2.Spring Boot支持JSP
Spring Boot Reference Documentation
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-template-engines

Template Engines
As well as REST web services, you can also use Spring MVC to serve dynamic HTML content. Spring MVC supports a variety of templating technologies, including Thymeleaf, FreeMarker, and JSPs. Also, many other templating engines include their own Spring MVC integrations.

Spring Boot includes auto-configuration support for the following templating engines:

FreeMarker

Groovy

Thymeleaf

Mustache

If possible, JSPs should be avoided. There are several known limitations when using them with embedded servlet containers.
如果可能,应该避免使用JSPs(各种副作用)。在embedded servlet containers【未确定此处和tomcat embed(7版本开始支持)是否为一回事】里使用有诸多已知限制。

Spring Boot Reference Documentation
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-jsp-limitations

JSP Limitations
When running a Spring Boot application that uses an embedded servlet container (and is packaged as an executable archive), there are some limitations in the JSP support.

With Jetty and Tomcat, it should work if you use war packaging. An executable war will work when launched with java -jar, and will also be deployable to any standard container. JSPs are not supported when using an executable jar.
在非嵌入式jetty和tomcat下,war包可以工作。可执行war包,用java -jar xxx.war,也可以工作,可以部署到各种标准容器中。使用可执行jar包(即java -jar xxx.jar[注意是jar不是war]),JSPs特性不能支持。{为什么不支持,可能和JSP的执行引擎Jasper2的运行机制或者路径判断有关吧?未深入研究}
策略:1.只能达成war包(不可执行的或者可执行的)
2.用容器或者java运行war包,支持JSPs。

Undertow does not support JSPs.
undertow直接不支持JSPs。

Creating a custom error.jsp page does not override the default view for error handling. Custom error pages should be used instead.

重要链接:
https://stackoverflow.com/questions/42154614/springboot-embedded-tomcat-and-tomcat-embed-jasper

posted @ 2020-10-15 13:13  任国强  阅读(199)  评论(0编辑  收藏  举报