springboot项目使用war包部署到tomcat

(在IDEA中使用外部tomcat)

1.修改打包方式

默认为jar包,将打包方式修改为war
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

2.移除springboot中内嵌的tomcat

删除spring-boot-starter-web依赖中的节点内容
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

3.添加依赖

servlet-api依赖
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
tomcat依赖
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

4.修改打包方式

springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

5.修改启动类,重写初始化方法

默认启动方法
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
修改为
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

6.打包部署

使用maven工具,点击package打包
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
打包完成后,在项目的target中生成
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
将war包拷贝到tomcat的webapps目录下
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

bin目录下,点击startup.bat启动tomcat
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
自动弹出cmd
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

注:没有tomcat环境变量的话使用.bat方式启动会一闪而过,使用exe启动可正常运行

springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

在IDEA中使用tomcat启动

1.在File-Settings中找到Application Servers

springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

2.点击图中加号添加tomcat-server

springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
选择tomcat安装路径
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

3.点击Edit Configurations

springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
在左侧Templates中找到Tomcat-server
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
选择local
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
在下拉框中选择
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
进入Deployment
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
点击加号,打开Artifact
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
选择.war
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
在下方修改项目名,或者使用默认
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
修改后会在Server中的URL自动变为修改路径
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
此处选择热部署,html改变后无需重新打包即可生效
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
配置好后生效,OK,就可以在这里直接启动了
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
启动成功,下方控制台显示输出信息
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

4.解决乱码问题

在tomcat启动项中的VM options添加这句话,以UTF-8形式运行
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)
显示正常
springboot使用war包部署到tomcat(在IDEA中使用外部tomcat)

相关文章:

  • 2021-11-18
  • 2022-12-23
  • 2022-01-03
  • 2021-11-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-02
  • 2021-04-15
  • 2021-04-08
  • 2021-11-16
  • 2021-10-01
相关资源
相似解决方案