我有 Spring Boot 应用程序,如果我从 IDE 运行主类,一切正常,应用程序工作正常。
如果我使用 java -jar MyApp-1.0.jar
从命令行启动生成的 JAR(通过 mvn clean install
),应用程序就会启动,但是当我转到 localhost:8080
时,它会显示 Whitelabel 错误页面:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Aug 02 14:21:00 CEST 2019
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/view/home.jsp
这就像 Maven 生成了一个错误的 JAR 文件。 你能帮我吗?
最佳答案
请在您的 application.properties 中定义前缀和后缀映射,如下所示并尝试
spring.mvc.view.prefix: /WEB-INF/jsps
spring.mvc.view.suffix: .jsp in your application.properties
请检查下面的文件以了解映射 https://github.com/hellokoding/springboot-jsp/blob/master/src/main/resources/application.properties
另请检查带有 jsp 的示例 springboot 项目,如下所示 https://hellokoding.com/spring-boot-hello-world-example-with-jsp/
已经在这里回答了Spring boot application displaying white label error when executing jar file
关于java - 为什么如果我从 IDE (Eclipse) 启动一个 Spring Boot 应用程序作为 Java 应用程序,它可以工作,但是当我从 CMD 启动它时,它会出现 Whitelabel 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57326458/