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啓動類同級新建一個類 如下:

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

最後是 重啓~ 然後就是搞定~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章