Running a SpringBoot Application as a Windows Service

The best way (that I’ve found) to run a SpringBoot application as a Windows service is to use the WinSW wrapper which lets you run any executable as a service. It really is falling off a log simple to set up you just need to download the wrapper, rename the executable and create a short XML configuration file.

Configuration

A sample configuration file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<service>
	<id>SpringServiceDemo</id>
	<name>Spring Service Demo</name>
	<description>This is a demo Spring install running as a service</description>
	<executable>C:\Program Files\Java\jdk1.8.0_141\bin\java.exe</executable>
	<arguments>-jar "%BASE%\SpringDemo.war"</arguments>
	<logpath>%BASE%\logs</logpath>
	<log mode="roll-by-size">
		<sizeThreshold>10240</sizeThreshold>
		<keepFiles>8</keepFiles>
	</log>
</service>

I’m packaging my app as a war file for technical reasons, usually you’d be using a jar file but either works. The log configuration is optional but I find it helps keep things neat.

Installation / Uninstallation

At an administrator command prompt just switch to the install directory and issue the command:

SpringDemo.exe install

Obviously switch install to uninstall for removal.