springBoot项目jar包改war包并部署到tomcat

springBoot项目jar包改war包并部署到tomcat

1、pom依赖

1、由jar改为war
修改前:

<packaging>jar</packaging>

修改后:

<packaging>war</packaging>

2、maven配置
添加build插件:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- 打war包配置 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.2</version>
            </plugin>
        </plugins>
    </build>

2、修改启动类

继承SpringBootServletInitializer并重写配置类configure

public class Application extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
        return builder.sources(Application.class);
    }
}

3、修改application.yml配置文件

3.1 没有项目根路径

没有设置访问的根路径,即参数server.servlet.context-path没有配置或为空

server:
  port: 8202
  servlet:
    context-path: 

1、在maven中打成war包
2、将war包复制到tomcat的webapps下
3、并将war更名为【项目名.war】
例:
helloWorld.war
4、到bin目录中执行startup.bat(windows)/startup.sh(linux)启动服务。
5、测试访问接口:http://localhost:8202/helloWorld/test

3.2 有项目根路径

没有设置访问的根路径,即参数server.servlet.context-path有配置值

server:
  port: 8202
  servlet:
    context-path: helloWorld

1、在maven中打成war包
2、将war包复制到tomcat的webapps下
3、并将war更名为【context-path值.war】,注意:war包名需要与server.servlet.context-path值一致
4、修改tomcat的配置文件conf/server.xml

1、修改Host标签
appBase值置空
2、修改Host标签内容,添加代码:
<Context path="【context-path值】" docBase="war包路径" reloadable="true"></Context>

例:

<Host name="localhost"  appBase=""
	      unpackWARs="true" autoDeploy="true">
		  <Context path="/restService/onecert" docBase="/server/apache-tomcat-8.5.99/webapps/onecert-0.0.1-SNAPSHOT.war" reloadable="true"></Context>
</Host>

5、到bin目录中执行startup.bat(windows)/startup.sh(linux)启动服务。
6、测试访问接口:http://localhost:8202/【context-path值】/test
例:
http://localhost:8202/helloWorld/test

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值