Table of Contents
- 1. Overview
- 2. Steps to Configure spring boot as windows service or process
- 3. Concussion
- 4. References
In this article, We will learn about how to run spring boot as windows service or process. We will use
winsw service wrapper to run spring boot application as service in window OS.
winsw is service wrapper which is useful to run a process as daemons.
2. Steps to Configure spring boot as windows service or process
Using following steps we can run java jar or spring boot jar file as window process.
Step 1: Download Service Wapper
winswservice wrapper from here. For example, we have download
Step 2: Rename Service Wapper
Step 3: Create Configuration XML file
my-spring-boot-service.xmlin the same location where
NOTE: Make sure that
.xmlfile name must be same, so our .exe file name is
- Here are some configuration related to services like service name, service id and description. here are more options about configuration XML file.
executableindicate the location of
java.exefile which will be responsible to execute .jar file. Write
java.exe‘s full path otherwise it service will throw an error like :
Error 1067: The process terminated unexpectedly.
argumentswhere is our actual command to execute .
jar, Our jar name is
- We can also change user context in which service will be run, Here is a document to change user context
<service> <id>my-spring-boot-service</id> <name>my-spring-boot-service</name> <description>Java Developer Zone - Spring boot as windows service example</description> <executable>C:\Program Files\Java\jre1.8.0_51\bin\java</executable> <arguments>-jar "%BASE%\demo.jar"</arguments> <logmode>rotate</logmode> </service>
Step 4: Copy Jar File
- Copy jar file at same directory where
my-spring-boot-service.xmlfiles are available.
It will look as below:
Step 5: Install Service
- Now open terminal, Go to the directory where our files are available and execute below command:
> my-spring-boot-service.exe install
2018-05-16 20:42:51,066 INFO - Installing the service with id 'my-spring-boot-service'
If service installs successfully, Let’s check in services inside windows:
Step 6: Start & Stop Service
> my-spring-boot-service.exe start
2018-05-16 20:52:50,395 INFO - Starting the service with id 'my-spring-boot-service'
> my-spring-boot-service.exe stop
2018-05-16 20:54:29,264 INFO - Stopping the service with id 'my-spring-boot-service'
Step 7: Uninstall Service
> my-spring-boot-service.exe uninstall
2018-05-16 20:50:37,897 INFO - Uninstalling the service with id 'my-spring-boot-service' 2018-05-16 20:50:37,906 WARN - The service with id 'my-spring-boot-service' is running. It may be impossible to uninstall it
In this article, We have learned steps install spring boot application as windows service using winsw windows service wrapper.