SpringBoot进行部署到云的Tomcat

xiaoxiao2021-02-27  171

SpringBoot打War包

默认SpringBoot打出来的是jar包,供直接运行,但是项目需要打成war包进行放到云服务的tomcat下进行运行。


按如下步骤进行

修改你的程序入口,去继承SpringBootServletInitializer

修改你的pom.xml进行更改。

1.

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>

2. 声明打成war包

<packaging>war</packaging>

3.移除启动的tomcat

<!-- Compile --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!--springboot 启动移除tomcat--> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> 开始打包项目Build–>Build Artifacted

到项目目录的 进行查找打成的war包

通过FilleZile将war包上传至服务器的webapp下,

然后通过http://47.93.254.222:8080/dd/ 进行访问你的项目。


附带Pom.xml的全部配置

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <!-- Your own application should inherit from spring-boot-starter-parent --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-samples</artifactId> <version>2.0.0.BUILD-SNAPSHOT</version> </parent> //打成war包 <packaging>war</packaging> <artifactId>spring-boot-sample-web-ui</artifactId> <name>Spring Boot Web UI Sample</name> <description>Spring Boot Web UI Sample</description> <url>http://projects.spring.io/spring-boot/</url> <organization> <name>Pivotal Software, Inc.</name> <url>http://www.spring.io</url> </organization> <properties> <main.basedir>${basedir}/../..</main.basedir> </properties> <dependencies> <!-- Compile --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!--springboot 启动移除tomcat--> <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-thymeleaf</artifactId> </dependency> <!-- Test --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- marked the embedded servlet container as provided --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
转载请注明原文地址: https://www.6miu.com/read-15786.html

最新回复(0)