platypus
platypus

Reputation: 25

How to hard-code values application.properties before application start

I need an efficient way to write and use property values that can be entered into an application.yml(properties)

It is necessary that the property values be hardcoded in the application configuration, regardless of whether they will be entered in the application file or not at all (entered values in application.yml(properties) should be ignored and only those values that are hardcoded in the application itself should be used) used)

Upvotes: 1

Views: 767

Answers (1)

Nikolas
Nikolas

Reputation: 44398

You can always pass the parameters to override the application.yml properties through the command-line parameters on the application start-up. Let's configure the server.port this way:

  • Standard Java application:

    java -jar application.jar --server.port=8090
    
  • Spring Boot 2.X application using Spring Boot Maven plugin and spring-boot:run command:

    mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8090"
    

This is both applicable ex. to a Docker file or run-configuration in your IDE.

Upvotes: 2

Related Questions