【发布时间】:2014-08-15 16:13:06
【问题描述】:
问题:
使用 Spring 4,我在访问网页时得到了这个
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Aug 15 16:41:29 BST 2014
There was an unexpected error (type=Not Found, status=404).
我有什么:
我有这个主类:
// src/main/java/abc/Main.java
package abc;
import abc.web.WebAppConfig;
import org.springframework.boot.SpringApplication;
public class Main {
public static void main(String[] args) {
SpringApplication.run(WebAppConfig.class);
}
}
然后我有了这个 WebAppConfig.class(目前只有一些配置注释):
// src/main/java/abc/web/WebAppConfig.java
package abc.web;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@EnableAutoConfiguration
public class WebAppConfig {
}
还有这个控制器 HomeController.java:
// src/main/java/abc/web/HomeController.java
package abc.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
@Controller
@RequestMapping("/")
public class HomeController {
@RequestMapping(method = GET)
public String home() {
System.out.println("HELLO !!");
return "home";
}
}
你好!显示在日志中。
最后我在src/main/java/abc/webapp/home.html 有一个html 文件,只有一些html 标签,包括p 标签和Hello, world!。
问题:
我知道我错过了呈现视图的方式,但我在 stackoverflow 上搜索了几个问题,但尚未找到解决方案。
有人可以解释一下如何让 Spring 呈现网页吗?我错过了什么?
提前致谢:)
【问题讨论】:
-
请从请求中发布服务器日志。
标签: spring spring-mvc spring-boot