Search code examples
javaspringmavenportprofile

Where should I store ports? Simple Java application, Spring boot, maven


For local testing my app i use port 8080, but on AWS server need to use 5000.

I propose i need to have 2 profiles, for example application.yml and application_dev.yml. application.yml - port: 5000 application-dev.yml - port 8080

When i'll start app local with IDEA, run/debug configuration -> Active profile, write dev and that all. My app will start with port 8080. Local IDEA

With AWS server i use jar file, i upload builded jar file.

So... I checked :) jar file has both yml files. ... How correctly start app?

  1. I do nothing and my app will start with default profile application.yml with port 5000
  2. I should add something on server... i don't know... for example in Environment properties ... spring_profile application.yml. Now i use SERVER_PORT 5000 record. AWS server

Sorry, it's my first question... And i know my English sucks. Thanks for your time and kindness.

I'd like be glad for any information and links to articles on the topic.

I tried to create application.yml and applitation-dev.yml.

I don't tried to launch these on AWS server.


Solution

  • If you just want your application to start with a different port, you cand add a profile customization as you did, for instance:

    application-prod.yaml

    server:
      port: 50000
    

    Than start it activating the correct profile :

    java -Dspring.profiles.active=prod -jar target/your-app.jar
    

    And the application will override the port.

    Of course you can use the opposite approch, set the default port for production and activate a 'dev' profile for development.

    Hope everything is clear.

    Regards