DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Spring Boot: Testing Service Layer Code with JUnit 5 and Mockito, RESTful Web Services
  • Component Tests for Spring Cloud Microservices
  • How To Build Web Service Using Spring Boot 2.x

Trending

  • Decoding Database Speed: Essential Server Resources and Their Impact
  • Contract-Driven ML: The Missing Link to Trustworthy Machine Learning
  • Optimizing Cloud Costs With Serverless Architectures: A Technical Perspective
  • Building an AI Nutrition Coach With OpenAI, Gradio, and gTTS
  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Boot as a Windows Service in 5 Minutes

Spring Boot as a Windows Service in 5 Minutes

We take a look at how you can get up and running quickly using Spring Boot to create a Windows service as well as pass configuration details.

By 
Martin Farrell user avatar
Martin Farrell
·
Dec. 18, 17 · Tutorial
Likes (27)
Comment
Save
Tweet
Share
87.5K Views

Join the DZone community and get the full member experience.

Join For Free

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

Getting Started

 Section 59 of the Spring Boot documentation is about Installing Spring Boot applications, and it points you toward a GitHub page. This example uses that project for inspiration.

Project

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.

Running Spring Boot From Command Line

Running Spring Boot from the command line

We can then see our application running:

Spring MVC Example

Spring MVC example 

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.
Windows Service Directory

Windows service directory

  • 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:

Windows Service

Windows service

  • To uninstall, we run – gs-serving-web-content.exe uninstall

Alternatives

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.

Conclusion

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.

Spring Framework Spring Boot Web Service

Published at DZone with permission of Martin Farrell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • Spring Boot: Testing Service Layer Code with JUnit 5 and Mockito, RESTful Web Services
  • Component Tests for Spring Cloud Microservices
  • How To Build Web Service Using Spring Boot 2.x

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: