Spring Boot发布方式

一、构建Jar包,命令行运行Spring Boot程序

    创建项目的时候选择以jar的方式构建,pom.xml中会有<packaging>jar</packaging>
        1.右键pom.xml->run as->Maven install;
        2.刷新target目录->copy 项目名-0.0.1.jar的目录->cmd cd到 jar目录-> java -jar 项目名-0.0.1.jar启动项目;

二、构建war包,发布到Tomcat

   1.将pom.xml中的<packaging>jar</packaging>换成<packaging>war</packaging>
   2.在pom.xml添加依赖:
            <dependency>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-starter-tomcat</artifactId>
            </dependency
   3.项目上出现红叉,右键项目—>maven->update project ->ok->红叉消失;
   4.让启动类xxxApplicaton继承 SpringBootServletInitializer;
   5.重写父类方法
           protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
                    return builder.sources(xxxApplication.class);
                }
    6.右键pom.xml->Run as->Maven clean;
    7.右键pom.xml->run as->Maven install;
    8.将target生成的war包放到tomcat的webapps中,启动tomcat。
            (注:访问的时候需要加上war包解压后的包名路径,eg:localhost:8080/文件名(项目名-0.0.1...)/)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值