1.导入javax.servlet-api
在项目的war包中的pom.xml中添加,因为大部分都是用的模块化的聚合工程
如果你的项目没用到直接在工程中的pom.xml添加以下内容就好
<packaging>war</packaging>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>RELEASE</version>
<scope>provided</scope>
</dependency>
至于很多人说的需要排除tomcat,我没弄项目也没什么问题,所以我也就不弄了
之后你需要对你的启动项目进行一些变动
application.class 同级目录下新建一个类名字随便取
继承
SpringBootServletInitializer
重写 configure
内容如下
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// 指向 application,使用web.xml运行应用程序
return builder.sources(Application.class);
}
2.配置tomcat
找到server.xml vim打开它 一般来说都是在conf的目录下
找到文件中的<host></host>
将其中改为如下内容,如果你有多个项目你不能这么配置,而是改为添加如下内容
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="/" reloadable="true" docBase="这个指向的文件夹需要创建,并且将路径填入"></Context>
</Host>
这些都配置之后你可以试着启动tomcat试试,想看到实时的返回信息可以在bin目录下使用
./catalina.sh run 但是这样启动你的终端关闭tomcat也会关闭
你测试了没问题再改用 ./startup.sh 启动就好了
以上是spring boot 打包成war包的启动方式关于jar启动很简单但是需要注意一些东西
使用 maven install 达成jar包之后,上传至云端启动方式需要改为
nohup java -jar **.jar&
如果你不是以一个服务器的话,你的终端关闭了通过jar启动的tomcat也会关闭
还有你需要注意你的端口不能重复,这样启动之后他会生成一个名为nohup.out文件
你的输出可以通过cat nohup.out查看