[Win服务器] SpringBoot项目如何简单快速部署Windows服务器上

195 0
Honkers 2025-4-26 19:06:59 | 显示全部楼层 |阅读模式

SpringBoot项目部署在Linux服务器上是非常简单的,直接运行就可以。但是有的时候我们需要将SpringBoot项目部署在windows服务器上,那么如何部署了?Spring官方推荐我们使用winsw在windwos服务器上运行SpringBoot项目。

winsw安装和配置

首先,在github上下载WinSW.NET4.exe和sample-minimal.xml文件,下载地址如下:

  1. https://github.com/winsw/winsw/releases/tag/v2.11.0
复制代码

下载完后,我们开始进行项目配置,这里我们以SpringBoot打包成jar包的形式为例,将打包后的文件命名为HelloSppring_Service.jar,将刚刚下载的WinSW.NET4.exe和sample-minimal.xml文件分别命名为HelloSppring_Service.exe和HelloSppring_Service.xml,将三个文件放到同一个文件夹下,如图所示


创建完文件后,我们需要配置HelloSppring_Service.xml,如图所示

  1. <service>
  2. <!-- ID of the service. It should be unique across the Windows system-->
  3. <id>HelloSppring_Service</id>
  4. <!-- Display name of the service -->
  5. <name>HelloSppring_Service Service (powered by WinSW)</name>
  6. <!-- Service description -->
  7. <description>This service is a service created from a minimal configuration</description>
  8. <!-- Path to the executable, which should be started -->
  9. <executable>java</executable>
  10. <!-- 指定启动的Jar及环境 -->
  11. <arguments>-jar HelloSppring_Service.jar</arguments>
  12. <!-- 开机启动 -->
  13. <startmode>Automatic</startmode>
  14. <!-- 日志配置,项目中以及配置了logback,所以在这里就不输出日志了 -->
  15. <logmode>none</logmode>
  16. </service>
复制代码

注意java中配置java前提是需要配置好环境变量,如没有配置则需要在此处配置指定jdk路径,到这里配置基本上已完成。

服务

winsw本质上是在windows服务器上创建一个运行SpringBoot项目的服务,类似.NET项目发布常用的IIS服务,通过服务来运行相关进程。前面我们已经配置好了项目,启动命令窗并定位到当前文件夹目录,运行创建服务命名

创建服务

  1. HelloSppring_Service.exe install
复制代码

创建完成后我们会在系统的管理-服务中看到当前创建服务,则说明服务创建成功,下一步启动服务,我们可以直接在服务管理中启动/停止/删除服务,也可以通过命令启动/停止/删除服务。

启动服务

  1. net start HelloSppring_Service
复制代码

停止服务

  1. net stop HelloSppring_Service
复制代码

删除服务

  1. HelloSppring_Service.exe uninstall
复制代码

如需要更新jar包,停止服务后直接替换掉对应的.jar包再重新启动服务

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Honkers

特级红客

关注
  • 3159
    主题
  • 36
    粉丝
  • 0
    关注
这家伙很懒,什么都没留下!

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行