linux服务器使用tomcat部署springboot项目

linux服务器使用tomcat部署springboot项目

一、项目达成war包

注意点:
1)maven文件中配置打包方式:<packaging>war</packaging>
2)修改打包名称,项目访问依赖此名称:在<build>中增加<finalName>photos</finalName>

二、将war包上传到tomcat目录webapps中,启动tomcat会自动解压

1)启动命令:sh bin/startup.sh
2)可使用rz命令上传war包。

三、存在的问题

  1. 现象

    项目启动后,tomcat访问正常,没有spring启动日志,项目访问报404异常。

  2. 原因分析

    springboot项目默认使用内置tomcat启动服务,如果需要外部tomcat启动需要屏蔽springboot中tomcat容器。

  3. 解决方案

    1)增加maven依赖
    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
    </dependency>
    
    2)修改启动器
    public class SpringbootApplication extends SpringBootServletInitializer {
    
        public static void main(String[] args) {
            SpringApplication.run(SpringbootApplication.class, args);
        }
        //重写configure方法
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
            return builder.sources(SpringbootApplication.class);
        }
    }
    
posted @   温故方能知新  阅读(946)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示