HTTP 状态 404 – 在 Spring Boot 中找不到 [英] HTTP Status 404 – Not Found in Spring boot
问题描述
我是弹簧靴的初学者.我想在spring boot中编写HelloWorld编程.我在运行项目时做了一个我得到的错误是 HTTP Status 404 – Not Found到目前为止我尝试过的我在下面附上了.pls,帮我解决问题写一个有效的方法.
I am a beginner of spring boot. I want to write the HelloWorld programming in spring boot. I did the one while running the project I got the error was HTTP Status 404 – Not Found what I tried so far I attached below.pls, help me to solve the problem write an efficient way.
控制器
@Controller
public class SecondController {
@GetMapping("/")
public String viewHomePage(Model model) {
return "index";
}
}
index.jsp
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Welcome to Jsp</h1>
</body>
</html>
application.properties
spring.mvc.view.prefix:/
spring.mvc.view.suffix:.jsp
推荐答案
您已在 pom.xml 文件中导入依赖项 spring-boot-starter-data-jpa
.所以你需要一个数据库.要解决这个问题,您可以使用 h2 数据库:
You have imported the dependency spring-boot-starter-data-jpa
in your pom.xml file. So you need a database. To solve this problem you can use a h2 database:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
或者,如果您一开始不需要它们,您可以暂时删除 spring-boot-starter-data-jpa
依赖项.如果你想再学习一个教程,我可以推荐这个 Spring 的教程.
Or you can remove the spring-boot-starter-data-jpa
dependency for a while if you don't need them at first. If you want to do another first tutorial, I can recommend this tutorial from Spring.
编辑:
您缺少使用 jsp 的两个必要依赖项:
You are missing two necessary dependencies to use jsp:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
现在您可以将 .jsp 文件放在 src/main/webapp/WEB-INF/jsp/
或 src/main/resources/META-INF/resources/WEB-INF/jsp/
文件夹并将属性 spring.mvc.view.prefix:/WEB-INF/jsp/
添加到 application.properties 文件中.
Now you can put your .jsp file in the src/main/webapp/WEB-INF/jsp/
or in the src/main/resources/META-INF/resources/WEB-INF/jsp/
folder and add the property spring.mvc.view.prefix:/WEB-INF/jsp/
to the application.properties file.
这篇关于HTTP 状态 404 – 在 Spring Boot 中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!