gpt4 book ai didi

java - Springboot Whitelabel 错误页面,状态为 404 : unable to resolve path of JSP

转载 作者:行者123 更新时间:2023-12-01 23:53:14 25 4
gpt4 key购买 nike

我正在开发一个 spring-boot 项目,我使用 JSP 文件并给出Whitelabel 错误页面出现意外错误(类型=未找到,状态=404)

我已将 JSP 放在/src/main/webapp/pages/中,并且已使用应用程序属性给出了路径。

它有几个模块,主要组件不包括 spring-boot 依赖项,它只包括所需的特定模块。从其他模块继承的代码已与 spring-boot 模块一起使用,因为它无法单独构建。

特定的子模块不包含 spring-boot 父模块作为父模块,因为必须在此时定义父模块。

pom.xml(由于隐私问题,一些作为依赖项继承的子模块必须从pom中删除)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.epic.cb</groupId>
<artifactId>EPICCB</artifactId>
<version>V1.00</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>M_EOD</artifactId>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.boot.eod.version>1.5.4.RELEASE</spring.boot.eod.version>
<spring.eod.version>4.3.4.RELEASE</spring.eod.version>
<apache.tomcat.version>7.0.55</apache.tomcat.version>
<com.epic.cb.version>V1.00</com.epic.cb.version>
<sql.version>6.2.1.jre8</sql.version>
<jquery.version>3.1.1</jquery.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.eod.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>${spring.boot.eod.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
<version>${spring.boot.eod.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${spring.boot.eod.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>${apache.tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>${jquery.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.eod.version}</version>
</dependency>

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${sql.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>${apache.tomcat.version}</version>
</dependency>
<dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>
</project>

应用程序属性

server.port=8589

spring.mvc.view.prefix=/WEB-INF/pages/
spring.mvc.view.suffix=.jsp

EodController.java

@Controller
public class EodController {

@Autowired
EodSchedulerService eodSchedulerService;

@ResponseBody
@RequestMapping(value = "/", method = {RequestMethod.GET})
public String viewMain() {
return "Hello World !!!";
}

@RequestMapping(value = "/viewEODDashboard", method = {RequestMethod.GET})
public String viewEODDashboard() {
return "eodTaskDashboard";
}

@RequestMapping(value = "/executeEodTasks", method = {RequestMethod.GET})
@ResponseStatus(code = HttpStatus.OK)
public void approveEODDashboard() {
eodSchedulerService.executeScheduledTasks();
}
}

EodStartup.java

@SpringBootApplication
@ComponentScan("com.epic.cb.*")
public class EodStartup {

public EodStartup() {
//default constructor
}

public static void main(String[] args) throws Exception {
SpringApplication.run(EodStartup.class, args);
}
}

文件结构

├── src
├── main
| ├── java
│ │ └── com
│ │ └── epic
│ │ └── cb
│ │ └── eod
│ │ ├── EodStartup.java
│ │ └── controller
│ │ └── EodController.java
| |
│ ├── resources
│ | └── application.properties
│ └── webapp
│ └── WEB-INF
│ └── pages
│ └── eodTaskDashboard.jsp

以下是我提到的一些链接:

  1. Why do I always get Whitelabel Error Page with status "404" while running a simple Spring Boot Application
  2. Spring Boot JSP 404.Whitelabel Error Page
  3. Tomcat-embed-jasper added but jsp pages Whitelabel 404 Error
  4. Getting whitelabel error page when running springboot application等等..

我想用JSP解决这个问题。 (因为它还有其他几个选项,例如:Thymeleaf)

提前谢谢您!

最佳答案

如果您使用嵌入式 tomcat,请尝试提供此依赖项,其范围为“已提供”:

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>

对于JSP文件,放入src/main/webapp/WEB-INF/pages/并将资源放在 /src/main/resources/ 下Springboot 希望维护此层次结构,但从您的项目结构来看,它是不正确的。

关于java - Springboot Whitelabel 错误页面,状态为 404 : unable to resolve path of JSP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58213535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com