Spring无法找到我的JSP文件,即使一切都很好

twh00eeo  于 10个月前  发布在  Spring
关注(0)|答案(1)|浏览(93)

我得到了whitelabel错误页面,而returing我的jsp文件,因为Spring是无法找到它。我到处咨询,做了所有提到的事情,仍然不能解决这个错误。我尝试的事情:
1.把我的jsp文件放在WEB-INF中的webapp文件夹中
1.在pom.xml中添加了tomcat embed碧玉
1.我通过添加@ResponseBody来确保Map是正确的。
我试着做一个简单的控制器类来返回一个简单的jsp文件。

@Controller
public class sayHelloContainer {

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }
}

字符串
但无论我做什么,我总是得到这个错误。

"Path with "WEB-INF" or "META-INF": [webapp/WEB-INF/views/hello.jsp]"
Resource not found
Exiting from "FORWARD" dispatch, status 404


我知道这意味着它找不到我的JSP文件,但据我所知,一切都很好。
这是我的application.properties

spring.mvc.view.prefix=/webapp/WEB-INF/views/
spring.mvc.view.suffix=.jsp
logging.level.org.springframework=debug


下面是我的文件结构enter image description here
这是我的pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

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

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

bkkx9g8r

bkkx9g8r1#

不必在路径中包含webapp目录。
只需将您的属性设置为:

spring.mvc.view.prefix=/WEB-INF/views/

字符串

相关问题