In this Blog, I will try to illustrate steps to run Spring Boot application as a Windows Service.
To run Spring Boot application as a windows service we will be using
winsw: Windows service wrapper
To run Spring Boot application as a windows service we will be using
winsw: Windows service wrapper
Please follow below mentioned steps
Step1: Check out
the version of Microsoft .NET framework to determine correct winsw version for
the windows operating system.
To check Microsoft.NET framework version, Navigate to command prompt and run below mentioned command as shown below
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\full" /v version
If your .NET framework version is less than 3.5 then we need
to download winsw v2.1.1 else we can
download winsw v2.1.2
Step2: Download
the winsw and prepare required directory structure.
We can download the winsw from below mentioned link
From the above mentioned git hub repository download the WinSW.NET4.exe and sample-minimal.xml to a directory and name it “spring-boot-service”
Also rename WinSW.NET4.exe and sample-minimal.xml to spring-boot-service.exe and spring-boot-service.xml
Place your application war in the same folder (for example spring-boot-service.war)
Modify the spring-boot-service.xml file with proper values
As shown in above screen shot, give unique id for your service (For ex : spring-boot-service)
For the "executable" property give value till JAVA_HOME/java (i.e. folder where your java.exe file is present)
set the argument property as shown below
<arguments>-Dserver.port=9002 -Duser.timezone=UTC -Xms1024m -Xmx2048m -Dlogging.root=C:\test\spring-boot-service\logs\ -jar spring-boot-service.war</arguments>
Step3: winsw installation and configuration set up
Open command prompt as an administrator and navigate to directory where you placed winsw installation and configuration file as explained in the Step1 (for example spring-boot-service folder)
i) Execute spring-boot-service.exe install
ii)
Open windows “Services” as Administrator –
For Example in Windows 7, following is navigation path to
launch windows Services
Start -> Control Panel -> System and Security ->
Administrative Tools -> Services(Run as Administrator)
i)
Now in the Services Window, select the service,
right click and start
or in the command prompt run net start <service-name>
where service-name is unique id which you given in service.xml file
To delete a process run below sc command
sc delete <service
name>