Spring App不适用于JSP

时间:2016-09-19 22:54:52

标签: java spring jsp spring-mvc intellij-idea

我是Spring Framework的新手。试图创建一个基于Java的Spring MVC项目。这是我的主要应用程序类

@SpringBootApplication
@ComponentScan
public class DemoApplication {

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

}
@Controller
public class HelloController {

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

}

当我运行项目时,我收到错误

There was an unexpected error (type=Not Found, status=404).
No message available

为什么Spring无法显示JSP文件?

enter image description here

1 个答案:

答案 0 :(得分:0)

将以下内容添加到application.properties

spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp

编辑:您可以参考示例项目here

下面的步骤不是必需的,但值得一试。

根据另一个post,您需要以下依赖项

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