Java 当从IntelliJ运行时,JSP Spring启动工作,但当运行WAR时,页面为空
我的spring boot应用程序有一个问题:它在运行form IntelliJ或mvn clean spring boot:run时运行正常。 然而,当我用Java 当从IntelliJ运行时,JSP Spring启动工作,但当运行WAR时,页面为空,java,spring,maven,jsp,tomcat,Java,Spring,Maven,Jsp,Tomcat,我的spring boot应用程序有一个问题:它在运行form IntelliJ或mvn clean spring boot:run时运行正常。 然而,当我用man-package打包它时,它会提供一个空页面,忽略我的JSP 我在包装战争。我计划使用嵌入式tomcat运行该项目 my pom.xml: 4.0.0 org.springframework.boot spring启动程序父级 2.3.3.2发布 战争 com.some LetDesk网站 0.0.1-快照 某网站 某网站 UTF-
man-package
打包它时,它会提供一个空页面,忽略我的JSP
我在包装战争。我计划使用嵌入式tomcat运行该项目
my pom.xml:
4.0.0
org.springframework.boot
spring启动程序父级
2.3.3.2发布
战争
com.some
LetDesk网站
0.0.1-快照
某网站
某网站
UTF-8
UTF-8
11
javax.servlet
jstl
假如
org.springframework.boot
弹簧靴开发工具
org.apache.tomcat.embed
汤姆卡特·贾斯珀
假如
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动机tomcat
假如
org.projectlombok
龙目
1.18.12
假如
org.springframework.boot
弹簧起动试验
测试
javax.servlet.jsp.jstl
JSTLAPI
1.2
servlet api
javax.servlet
jsp api
javax.servlet.jsp
src/main/webapp
src/main/resources
maven战争插件
2.3
目标
src\main\webapp\WEB-INF\WEB.xml
org.springframework.boot
springbootmaven插件
我的主要班级:
@springboot应用程序
公共类SomeWebsiteApplication扩展了SpringBootServletInitializer{
@凌驾
受保护的SpringApplicationBuilder配置(SpringApplicationBuilder应用程序){
返回application.sources(SomeWebsiteApplication.class);
}
公共静态void main(字符串[]args){
run(SomeWebsiteApplication.class,args);
}
}
控制器:
@GetMapping({”/“,“/hello”})
公共字符串hello(最终模型,
@RequestParam(value=“name”,
必需=错误,
defaultValue=“World”)最终字符串名称){
model.addAttribute(“name”,name);
log.info(“称为主页”);
返回“索引”;
}
}
我的jsp(位于src/main/webapp/WEB-INF/jsp/index.jsp
):
我花了好几个小时试图找到解决方案,但是没有用Spring Boot是一个框架,您现在没有遵循通常的惯例。如果您计划使用嵌入式Tomcat运行,您应该使用mojo而不是maven war插件
。这也意味着springbootstartertomcat
必须是compile
,并且您不需要从pom.xml
中获得很多东西
您当前的设置过于复杂,因为您正在构建一个应该部署到现有Tomcat中的WAR。你可能想从更简单的事情开始
您的jsp文件位于哪里?在
src/main/webapp/WEB-INF/jsp/index.jsp中删除您拥有的war插件和资源,您不需要它。为什么要使用web.xml
?您正在使用基于java的配置。另外,还可以放弃WebConfig
,将spring.mvc.view.prefix
和spring.mvc.view.suffix
添加到应用程序.properties
中,使用您现在在WebConfig
中的设置。谢谢!我有pom.xml,结果简单多了。:)
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello ${name}!</title>
<meta class="foundation-mq">
<link rel="stylesheet" href="css/app.css">
</head>
<body>
<div class="pageWithoutFooter">
<jsp:include page="NavigationElements/topNavigation.jsp"/>
<h2 class="hello-title">Hello ${name}!</h2>
<input type="button" value="Hi there!">
</div>
<jsp:include page="NavigationElements/footerNavigation.jsp"/>
</body>
</html>