Spring Boot是否可以通过独立的JAR包装提供JSP服务 [英] Is it possible with Spring Boot to serve up JSPs with a stand alone JAR packaging

查看:90
本文介绍了Spring Boot是否可以通过独立的JAR包装提供JSP服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用JSP将Spring Boot构建为jar包装.我构建了项目,并且使用此命令运行它时运行正常

I try to build Spring Boot with JSP to jar packaging. I build project and it works fine when I run it with this commands

$ mvn软件包

$ java -jar target/mymodule-0.0.1-SNAPSHOT.jar

但是当我进入目标目录($ cd目标)并尝试

but when I go to target directory ($cd target) and try

$ java -jar mymodule-0.0.1-SNAPSHOT.jar

应用程序运行正常,但是当我打开浏览器并尝试打开页面时,出现错误出现意外错误(类型=未找到,状态= 404). /WEB-INF/jsp/index.jsp"

the application runs fine but when I open browser and try to open the page I get error "There was an unexpected error (type=Not Found, status=404). /WEB-INF/jsp/index.jsp"

我发现了这个问题,但是当我尝试时,我遇到了同样的问题

I found this question, but when I try it I met the same problem Is it possible with Spring Boot to serve up JSPs with a JAR packaging

我的问题是为什么当我尝试时它会起作用

My questions is Why it works when I try

$ java -jar target/mymodule-0.0.1-SNAPSHOT.jar

,当我尝试

$ cd目标

$ java -jar mymodule-0.0.1-SNAPSHOT.jar

我该如何解决?

编辑

jar或目标目录中没有WEB-INF目录,当我把它放在那里时无济于事

There is not WEB-INF directory into jar or target directory and when I put it there it doesn't help

推荐答案

如果您使用的是嵌入式Tomcat,则Spring Boot

If you are using embedded Tomcat, Spring Boot doesn't support using JSPs in an executable jar:

对于Tomcat,如果您使用war打包,它应该可以工作,即可执行的war将可以工作,并且还可以部署到标准容器(不限于但包括Tomcat).可执行jar由于Tomcat中的硬编码文件模式而无法工作.

With Tomcat it should work if you use war packaging, i.e. an executable war will work, and will also be deployable to a standard container (not limited to, but including Tomcat). An executable jar will not work because of a hard coded file pattern in Tomcat.

当您尝试java -jar target/mymodule-0.0.1-SNAPSHOT.jar时它可以工作,因为JSP在src/main/webapp的文件系统上可用,Spring Boot将该JSP配置为文档根目录,以便在开发过程中使用.当您移至目标目录时,src/main/webapp文件夹不再可用,因此JSP停止工作.

It works when you try java -jar target/mymodule-0.0.1-SNAPSHOT.jar because the JSPs are available on the filesystem from src/main/webapp which Spring Boot configures as a document root for convenience during development. When you move into the target directory, the src/main/webapp folder is no longer available so the JSPs stop working.

这篇关于Spring Boot是否可以通过独立的JAR包装提供JSP服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆