在之前写过一篇博客关于ssm项目远程部署
地址:在这里
该教程是基于上篇,只是有部分修改而已。
Springboot 远程部署需要修改一下几点:
1、POM文件
(1)打包方式,这里将jar —> war
(2)关于依赖
springboot由于内置了tomcat,所以在使用war包部署是需要移除内置tomcat,并添加servlet容器支持。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <dependencies> <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.apache.tomcat</groupId> <artifactId>tomcat-servlet-api</artifactId> <version>8.0.36</version> <scope>provided</scope> </dependency> </dependencies>
|
二、SpringbootApplication启动类
启动类需要继承 SpringBootServletInitializer 类,并且重写configure 方法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication public class HelloSpringbootApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(HelloSpringbootApplication.class); } public static void main(String[] args) throws Exception { SpringApplication.run(HelloSpringbootApplication.class, args); } }
|
只需以上两部就可以完成Springboot项目远程部署。
转载自:https://blog.csdn.net/android_ztz/article/details/79262416