Manage a Spring Boot application as a Windows Service
You need Gradle to build the project and a simple .\gradlew.bat winswPackage
at the root will do.
There is no need for Spring Boot Daemon on Unix thanks to the native Spring Boot support from 1.3 onwards.
The windows
distribution uses winsw
.
Warning
|
You need to install the .NET framework on the target machine first.
|
To install the application as a service, extract the distribution zip somewhere and open a shell with administrative rights in that directory.
install.bat
Once the service has been installed, you can start it the usual way, that is:
Or, How to convert your application into a Windows Service.
To enable running your own Spring Boot applications as a Windows Service:
-
add
io.github.awghdbs:spring-boot-daemon-integration
as a dependency -
copy, unaltered, the
dist
directory fromspring-boot-daemon-sample/src/main
into your own application sources -
add the following properties and repositories to your
build.gradle
, updating the values to suit:ext { winswVersion = '2.2.0' bootJarName = "${project.name}-${project.version}.jar" distServiceName = "${project.name}" distServiceDisplayName = 'Sample Spring Boot App' (2) distServiceDescription = 'Demonstrate how to integrate a Spring Boot app as a Windows Service' (3) distJar = "lib\\${bootJarName}" distStartClass = 'net.nicoll.SampleApplication' (1) distJmxPort = '50201' (4) } repositories { maven{ url 'http://repo.jenkins-ci.org/releases/' } } configurations { winsw { transitive = false } } dependencies { implementation project(':spring-boot-daemon-integration') implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-actuator' // WinSW winsw "com.sun.winsw:winsw:${winswVersion}:bin@exe" }
-
Your Spring Boot application class
-
The name that shows in the Windows Services Control Panel
-
The longer description that shows in the Windows Services Control Panel
-
The JMX Port on the machine that will be assigned to the server, must not conflict with another usage and is required to be able to shutdown the service
-
-
change bootJar task to use
PropertiesLauncher
, and addwinswPackage
task to yourbuild.gradle