2016-09-19 16 views
0

我是Spring Framework的新手。試圖製作一個基於Java的Spring MVC項目。這是我的主應用程序類Spring App不能使用JSP

@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 

爲什麼春天不能顯示JSP文件?

enter image description here

+0

下載一個工作項目和工作過這一點。從零開始設置彈簧項目時,一百萬件事情可能會出錯 – Snickers3192

+0

我可以在哪裏下載它? –

+0

他們的網站怎麼樣???!@ ??? https://spring.io/guides/gs/serving-web-content/ – Snickers3192

回答

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> 
+0

我試過了。它不起作用 –

+0

匹配文件夾結構。將hello.jsp移動到WEB-INF/jsp文件夾 – sidgate

+0

我添加了屬性,依賴關係並將我的jsp文件移動到了WEB-INF/jsp文件夾中,但它仍然不起作用。 –