Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Sep 04 17:58:31 CST 2018
There was an unexpected error (type=Not Found, status=404)
然后是解决办法:
1.pom.xml文件中的红色部分注释掉,或者直接拷贝下面的依赖
<!-- tomcat 的支持. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!--<scope>provided</scope> idea需要注释掉,idea编译的时候找不到provided包-->
</dependency>
2.在和spring-boot启动类同级新建一个类 如下:
适应于spring-boot 1.x的版本使用如下
@Configuration
public class CommonConfiguration {
@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
ConfigurableEmbeddedServletContainer factory = new TomcatEmbeddedServletContainerFactory();
factory.setDocumentRoot(new File("E:\\idea_workspace\\my-springboot-jsp\\src\\main\\webapp"));
return (EmbeddedServletContainerFactory) factory;
}
}
spring-boot2.x版本
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.setDocumentRoot(new File("E:\\demo\\src\\main\\webapp"));
return factory;
}