tomcat 部署步骤总结【初学java如有错误,请不吝赐教】

本文详细介绍了使用SpringBoot框架结合Tomcat部署微服务的具体步骤与常见问题解决方法,包括配置、打包、多实例部署等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 由于最近公司启动了微服务项目,使用框架springcloud搭建微服务,因此开始了解java。 由于工作中用的基本为apache、nginx,发现java程序需要部署在tomcat下,因此开始漫长的 tomcat“采”坑之路

首先说先项目基本情况
  1. 微服务的基本框架需要部署在tomcat下
  2. 基础业务也用java来实现【可选】
  3. 业务服务器部署两台
  4. 使用springboot开发项目

在部署tomcat时,遇到几个问题如下:
  1. ​如何打包
  2. 如何部署
  3. 部署之后无效果
  4. 两台相同业务服务部署出错

针对以上问题,总结下自己的坑:


第1步搭建springboot项目
本人大家eureka服务注册于发现,中间涉及到不需要的代码可忽略
  1. 项目搭建完成后 需要将启动程序设置为springbootapplication,采用注解方式,并添加依赖
  2. 更新启动类集成springbootserletinitiallizer
  3. 重新config方法





第2步:取消其他类中springbootapplication配置




第3步:在application.properties中配置 default-domain
即使是同一个服务 ,不同端口部署也需要修改此配置,如果在同一个服务器上部署多个服务会导致出错



第4步 更新pom文件
  1. 打包方式更新为war为了部署
  2. eureka-server 配置是为了服务注册与发现,此处可忽略,不影响到部署
  3. 注意,本人搭建项目中没有tomcat 的import ,因此如果此处有tomcat 请注释掉




  1. ​这个插件难道是为了maven的package打包工具吗?我猜




第5步开始打包
如果有这个插件就双击,如果没有 应该去安装吧





打包出现BUILD SUCCESS 表示打包成功了




对我这种初次使用tomcat的用户来说,简直了。。。 Tomcat 配置内容还是要了解下,否则一头雾水
当然,如果你像我这样一头雾水也能配置成功,就忽略,当心给自己挖坑
  1. ​对应单个服务配置,需要修改的是端口号及服务路径,就是war包放置的位置
  2. 初次之外,增加了Context的配置,用于指定服务包路径
<Context docBase="servicehi-0.0.1-8762.war" path="/" reloadable="true" debug="0" privileged="true" />


完整的server.xml文件如下
附上本人的server.xml供大家参考

<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8769" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->

<Service name="Catalina">
<Connector port="8762" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="servicehi-0.0.1-8762.war" path="/" reloadable="true" debug="0" privileged="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_8762_log" suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s %b" />

</Host>
</Engine>
</Service>

<Service name="Catalina2">
<Connector port="8763" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

<Engine name="Catalina2" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>

<Host name="localhost" appBase="webapps2"
unpackWARs="true" autoDeploy="true">
<Context docBase="servicehi-0.0.1-8763.war" path="/" reloadable="true" debug="0" privileged="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_8763_log" suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s %b" />

</Host>
</Engine>
</Service>


</Server>








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值