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


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

一、项目达成war包

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

二、将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依赖
    
                org.springframework.boot
                spring-boot-starter-tomcat
                provided
    
    
    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);
        }
    }