centos环境下使用tomcat 部署SpringBoot的war包_Tomcat

这篇文章主要介绍了centos环境下使用tomcat 部署SpringBoot的war包的相关资料,本文通过实例代码给大家讲解的很详细,对tomcat 部署SpringBoot 的war包相关知识感兴趣的朋友一起看看吧

准备war包

一、准备好已有的SpringBoot工程,在pom中添加依赖

1)设置打包格式为war

 <packaging>war</packaging>

2)排除SpringBoot内嵌的tomcat

 <!-- 以war包部署的形式需要排除内嵌的tomcat -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
		</dependency>

3)配置插件

由原来的

<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

配置成

<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<fork>true</fork>
					<!-- 增加jvm参数 -->
					<jvmArguments>Dfile.encoding=UTF-8</jvmArguments>
					<!-- 指定入口类 -->
					<mainClass>com.peko.filemanager.Application</mainClass>
				</configuration>
			</plugin>
		</plugins>
	</build>

二、配置启动类

由原来的

@SpringBootApplication
public class Application{
 
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

配置成

@SpringBootApplication
public class Application extends SpringBootServletInitializer {
 
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
 
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
		return builder.sources(Application.class);
	}
}

三、用maven工具打包

先clean一下,再package

图片[1]-centos环境下使用tomcat 部署SpringBoot的war包_Tomcat-安全小天地

成功之后即可在target文件夹里找到打包好的war包

图片[2]-centos环境下使用tomcat 部署SpringBoot的war包_Tomcat-安全小天地

复制出来,然后可以改名字,这里我改成了helloworld.war

部署到centos上的tomcat

一、首先得安装tomcat

https://blog.csdn.net/piano_diano/article/details/116938060

二、将war包利用sftp工具上传到 tomcat/webapps 下

图片[3]-centos环境下使用tomcat 部署SpringBoot的war包_Tomcat-安全小天地

重启tomcat

systemctl restart tomcat

然后打开tomcat的管理界面

图片[4]-centos环境下使用tomcat 部署SpringBoot的war包_Tomcat-安全小天地

图片[5]-centos环境下使用tomcat 部署SpringBoot的war包_Tomcat-安全小天地

可以看到项目处于启动状态,如果是处于关闭状态,就去看tomcat/logs下的日志,报了什么错

注意:如果是以war部署在tomcat中,那么原本我们在yml文件中配置的端口号等信息是作废的

helloworld项目地址:https://gitee.com/ShyHour/hello-world

以上就是centos环境下使用tomcat 部署SpringBoot的war包的详细内容,更多关于tomcat 部署SpringBoot 的war包的资料请关注安全小天地其它相关文章!

------本文已结束,感谢您的阅读------
THE END
喜欢就支持一下吧
点赞5 分享
评论 抢沙发
头像
善语结善缘,恶语伤人心
提交
头像

昵称

取消
昵称常用语 夸夸
夸夸
还有吗!没看够!
表情图片

    暂无评论内容