【发布时间】:2017-07-12 14:29:44
【问题描述】:
我从here 运行 spring-boot-sample-web-static 项目,对 pom 进行了修改
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
并添加了此类以从同一 static 文件夹位置提供重复页面 index2.html:
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class Rester {
@RequestMapping(value = "/rand", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
private RandomObj jsonEndpoint() {
return new RandomObj();
}
@RequestMapping(value = "/tw")
public String somePg() {
return "index2";
}
}
json url 工作正常,但是当我尝试访问 localhost:8080/tw 时,我得到一个空白页面,并且控制台中出现此错误:
2017-02-22 15:37:22.076 ERROR 21494 --- [nio-8080-exec-9] o.s.boot.web.support.ErrorPageFilter : Cannot forward to error page for request [/tw] as the response has already been committed. As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false
我做错了吗?
【问题讨论】:
-
你并不需要依赖tomcat,spring starter web & thymeleaf 应该可以。
-
thymeloaf不是必需的。只需将index.html放入src/main/resources/static/文件夹,静态html 就完成了!
标签: java spring-boot