How to run spring boot app as windows service (winsw)
👋 Hey there! I’m Shohanur Rahman!
I’m a backend developer with over 5.5 years of experience in building scalable and efficient web applications. My work focuses on Java, Spring Boot, and microservices architecture, where I love designing robust API solutions and creating secure middleware for complex integrations.
💼 What I Do Backend Development: Expert in Spring Boot, Spring Cloud, and Spring WebFlux, I create high-performance microservices that drive seamless user experiences. Cloud & DevOps: AWS enthusiast, skilled in using EC2, S3, RDS, and Docker to design scalable and reliable cloud infrastructures. Digital Security: Passionate about securing applications with OAuth2, Keycloak, and digital signatures for data integrity and privacy. 🚀 Current Projects I’m currently working on API integrations with Spring Cloud Gateway and designing an e-invoicing middleware. My projects often involve asynchronous processing, digital signature implementations, and ensuring high standards of security.
📝 Why I Write I enjoy sharing what I’ve learned through blog posts, covering everything from backend design to API security and cloud best practices. Check out my posts if you’re into backend dev, cloud tech, or digital security!
Step 1: Download WinSW
Go to the WinSW GitHub Releases page.
Download the latest
.exefile (e.g.,WinSW-x64.exe).
Step 2: Rename the .exe File
Rename the downloaded
.exefile to match your application name. For example:- If your Spring Boot application is named
MyApp, rename it toMyApp.exe.
- If your Spring Boot application is named
Step 3: Create a Configuration File
In the same directory as your renamed
.exefile, create an XML configuration file with the same name as the.exefile, but with an.xmlextension. For example:MyApp.xml.
Add the following content to the XML file:
<service>
<id>MyApp</id>
<name>My Application</name>
<description>This is my Spring Boot application running as a Windows service.</description>
<!-- Path to the Java executable -->
<executable>C:\path\to\java.exe</executable>
<!-- Path to your Spring Boot JAR -->
<arguments>-jar C:\path\to\your-spring-boot-app.jar</arguments>
<!-- Optionally define working directory -->
<workingdirectory>C:\path\to</workingdirectory>
<!-- Logging -->
<logmode>roll</logmode>
</service>
Replace
C:\path\to\java.exewith the path to your Java installation.Replace
C:\path\to\your-spring-boot-app.jarwith the full path to your Spring Boot JAR file.
Step 4: Place Your Spring Boot JAR File
- Ensure your Spring Boot application's JAR file is located at the specified path in the XML file.
Step 5: Test the Configuration
Open a Command Prompt as Administrator.
Navigate to the directory containing the
.exeand.xmlfiles.Run the following command to test:
MyApp.exe installStart the service:
MyApp.exe startTo check the status of the service:
MyApp.exe statusStop the service if needed:
MyApp.exe stop
Step 6: Verify the Service
Open the Windows Services Manager:
- Press
Win + R, typeservices.msc, and hit Enter.
- Press
Look for your service by the name you specified in the XML file.
Start or stop the service from the Services Manager to confirm it works.
Step 7: Optional - Configure Automatic Startup
Set the service to start automatically:
Open the Services Manager (
services.msc).Right-click your service and select Properties.
Change the Startup type to Automatic.
Step 8: Logs and Troubleshooting
Logs are typically stored in the same directory as the
.exefile, with files likeMyApp.out.logandMyApp.err.log.Check these files for any errors if the service does not start correctly.