I recently had to deploy a Spring Boot application as a Windows service and am surprised how easy it was using winsw. I’d previously written about using procrun – Java Programs as Windows Services, but winsw is much easier
I'm going to use the Spring IO “Serving Web Content” project as a starting point, so go to the webpage and download the example from GIT or as a ZIP file.
We can then see our application running:
Wrapping as a Windows Service
- Download winsw from GitHub – remember to choose the correct version depending on the version of .NET you are running
- Create a Windows service directory and copy the EXE to this location.
- I renamed the gs-serving-web-content-0.1.0.jar to gs-serving-web-content.jar
- Rename the winsw EXE from WinSW.NET4.exe to gs-serving-web-content.exe
- Create a XML file named gs-serving-web-content.xml with the following content –
<?xml version="1.0" encoding="UTF-8"?> <service> <id>gs-serving-web-content</id> <name>gs-serving-web-content</name> <description>gs-serving-web-content Windows Service</description> <executable>java</executable> <arguments>-jar "gs-serving-web-content.jar"</arguments> <logmode>rotate</logmode> </service>
- We can then install with
gs-serving-web-content.exe install(you may need to run as administrator)
- We can then run this as a Windows service:
- To uninstall, we run – gs-serving-web-content.exe uninstall
I looked at procrun as an alternative wrapper for Spring Boot but couldn't get it to work. It probably can, but it needs more time.
I'm really impressed with winsw for installing Spring Boot applications as Windows services. It's really simple, and you can pass external application.properties files in through the XML configuration.