1:修改pom.xml
将“jar”改为“war”
<packaging>war</packaging>
将:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
修改为:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--打包的时候可以不用包进去,别的设施会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。
相当于compile,但是打包阶段做了exclude操作 java项目www.fhadmin.org-->
<scope>provided</scope></dependency>
修改build节点下的<plugin>将:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
改为:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 发布linux服务包,直接用linux的servic命令启动 -->
<executable>true</executable>
</configuration>
</plugin>
2:修改启动类:
//java项目www.fhadmin.org
public class Application extends SpringBootServletInitializer{ public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { // 注意这里要指向原先用main方法执行的Application启动类
return builder.sources(Application.class);
}
}