3 Ways to Change Default 8080 Port in Spring Boot


By default, all applications that you create using Spring Boot will run on Port 8080, if you want your application to run on some other port, you need to add server.port property in the application.properties file located in the resources folder.



1. Change default 8080 Port using configuration file

  1. Go to src > main > resources package in your project,
  2. If you have a application.properties file,

    server.port=<custom_port_no>

  3. If you have application.yml file,

    server:
       port: <custom_port_no>

  4. Save the file.
  5. Run your Spring Boot app and it should now run on the custom port you set.
Change Spring Boot Default 8080 Port Example


2. Change default 8080 Port using VM Argument in IDE

You can also change the default port using the VM Argument, add it to your IDE,

IntelliJ IDE
  • Go to Menu: Run,
  • Select Edit Configurations.
  • Now in VM options add -Dserver.port=<custom_port_number>

Visual Studo Code IDE:
  • Open launch.json file under .vscode directory
  • Add the below "vmArgs": "-Dserver.port=<custom_port_number>"
Add Custom Port VS Code Spring Boot App

Eclipse IDE
  • Right Click on your Project,
  • Select Run Configurations,
  • Add "-Dserver.port=<custom_port_number>" under VM Arguments


3. Change default 8080 Port while running the jar file:

When you are executing your jar file app, you can pass the option --server.port

Example:

% java -jar my/jar/path/my-boot-app.jar --server.port=8070


Have Questions? Post them here!
Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.