Window Server 部署Spring boot应用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gdp12315/article/details/82353941

背景

使用Spring Boot开发的Web项目,打包生成了一个jar包,希望能部署在Windows Server服务器中

前期方案

1、Spring Boot生成的jar包,可以直接用java -jar运行,通常还需要指定运行参数,并且运行的Dos界面会保留在任务栏中,没有后台运行

2、写一个bat批处理文件,里面写java -jar运行程序,将运行的命令写在里面,每次需要启动直接运行就行,不需要重复输入参数

最终方案

生产环境中,服务最好能够自动运行,出现重大错误后,能重启自启动

使用WinSW
WinSW是一个开源项目,程序以及源码可以在Git Hub中下载:https://github.com/kohsuke/winsw/releases

winsw是一个可以将任何应用程序注册成服务的软件

使用方法:
1、下载exe文件,假设改名成winsw.exe

2、同目录下创建一个同名的xml文件,如winsw.xml

其中参数自己看一下就可以了

<configuration>
  <id>MyServer</id>
  <!-- Display name of the service -->
  <name>MyServer Spring boot</name>
  <!-- Service description -->
  <description>This service is a service cratead for xxx</description>

  <!-- Path to the executable, which should be started -->
  <executable>java</executable>
  <arguments>-jar myserver-0.0.1-SNAPSHOT.jar -Dspring.config.location=file:./application.properties</arguments>

</configuration>

3、使用cmd,用cd命令转到winsw.exe所在文件夹,然后执行命令

安装服务命令:MyServer.exe install

卸载服务命令:MyServer.exe uninstall

4、打开系统服务功能:运行——输入services.msc,即可看见自己命名的服务myApp

5、设置服务为自动,并启用即可

猜你喜欢

转载自blog.csdn.net/gdp12315/article/details/82353941