spring-boot 学习 idea编译器使用main方法启动访问不到jsp页面,而使用eclipse可以,解决办法.

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;
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值