Java異常處理004:Springboot項目在tomcat下正常啟動,但是無法訪問(頁面和接口)


Java異常處理004:Springboot項目在tomcat下正常啟動,但是無法訪問(頁面和接口)

 

解決方案:

第一步,在POM.XML文件引入依賴

        <!-- 打war包時加入此項, 告訴spring-boot tomcat相關jar包用外部的,不要打進去 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
       <!-- springboot自帶的tomcat並沒有攜帶tomcat-embed-jasper的依賴,如果不引入tomcat-embed-jasper依賴,使用SPringboot啟動項目則會無法成功-->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

第二部,修改Springboot啟動類,繼承SpringBootServletInitializer類(作用是為了支持可以不使用web.xml)

public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}
改成
public class DemoApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

對SpringBootServletInitializer類的理解,請參考:https://blog.csdn.net/zq17865815296/article/details/79464403


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM