🚀 Level Up Your Java Skills!
Love simple and clear coding tutorials? Join the Ram N Java family for more!
SUBSCRIBE NOWChange Spring Boot Port and Context Path Fast
By default, every Spring Boot application starts on port 8080 with a root path. But what if you want to run multiple apps or just want a custom URL? It's much easier than you think!
The application.properties Way
The most common way for beginners to change these settings is by editing the application.properties file located in your src/main/resources folder.
Two Simple Lines of Code
Just add these two lines to customize your app:
server.port=9090— Sets the port.server.servlet.context-path=/myapp— Sets the base URL.
Why is this useful?
When you set a Context Path, your URLs will change from localhost:8080/users to something more descriptive like localhost:9090/myapp/users. This is essential when deploying professional applications!
Quick Tip
Always make sure the port you choose isn't being used by another program, or your application will fail to start.
No comments:
Post a Comment