1. Overview

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
  • Download winsw service wrapper from here. For example, we have download winsw-2.1.2-bin.exe
Step 2: Rename Service Wapper
  • Rename winsw-2.1.2-bin.exe to my-spring-boot-service.exe
Step 3: Create Configuration XML file
  • Create my-spring-boot-service.xml in the same location where my-spring-boot-service.exe is available.

NOTE: Make sure that .exe and .xml file name must be same, so our .exe file name is my-spring-boot-service.exe and  .xml is my-spring-boot-service.xml

my-spring-boot-service.xml
  • Here are some configuration related to services like service name, service id and description. here are more options about configuration XML  file.
  • executable indicate the location of java.exe file 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.

    <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.exe and my-spring-boot-service.xml files are available.

It will look as below:

spring boot window service - directory

spring boot window service – directory

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:

spring boot window service - my-spring-boot-service

spring boot window service – my-spring-boot-service

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

3. Concussion

In this article, We have learned steps install spring boot application as windows service using winsw windows service wrapper.

4. References

 

 

 

 

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes
No

Leave a Reply

Your email address will not be published. Required fields are marked *