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