Configuration and Properties : Spring Boot : Part 2 Externalising Configuration
I am a developer who loves Java, Spring, Quarkus, Micronaut, Open source, Microservices, Cloud
Search for a command to run...
I am a developer who loves Java, Spring, Quarkus, Micronaut, Open source, Microservices, Cloud
No comments yet. Be the first to comment.
Spring AI Tool Calling: From Chatbot to AI Agent with @Tool Your AI is smart. It knows an enormous amount. But it's frozen. It doesn't know what time it is right now. It doesn't know what's on your ca
Spring AI Advisors API Explained Series: Spring AI Complete Course — Lecture 4 of 12Reading Time: 8 minutesLevel: Intermediate Most developers stop at ChatClient. That is enough for demos. It is not
Working with Multiple AI Models in Spring AI Spring AI Complete Course — Lecture 3 of 12Previous: Lecture 2 — ChatClient API | Next: Lecture 4 — Advisors API In production AI applications, you rarel
Spring AI ChatClient API: The Fluent Heart of AI Integration Introduction If you've ever tried integrating AI models into a Java application, you know the pain. HTTP clients, API keys scattered everywhere, vendor-specific SDKs that never quite fit. W...
What is Spring AI? — Why Java Developers Need This in 2026 Every AI tutorial you see is in Python. LangChain, LlamaIndex, OpenAI SDK — all Python. But here's the uncomfortable truth: 80% of enterprise backends run Java. So who's building AI into thos...
Spring boot allows you to externalize your configuration properties. Above we saw, one way to do so using application.properties. There are various way to tell your application about properties required by your application i.e. it is not only limited to defining in application.properties .
Below are the ways you can define your properties. It is in order of preference which means , if same property is defined via two different ways , the one with higher precedence will be taken and the one with lower precedence value will be ignored.
The above list is taken from spring documentation present at https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
Tough it is good to know that there are several ways to define the properties which will be used for our application , it is hardly a chance that you will use all of them in our application . We will normally use them on need basis.
In order to verify the order of precedence , we can test it. In above list the number 4th (command line) and 15th (application.properties inside jar) are marked as bold. As per precedence order command line takes higher precedence over application.properties inside our jar file.
We already have application.properties with server.port =8081 , let’s add a command line argument of same before starting application and verify if our server starts at different port.
Currently our server starts at 8081 , say we want application to pick 8082 and ignore the value provided by application.properties (or application.yml) . We can provide command line arugument directly by invoking jar file made by build with command parameter like
java -jar user-service-0.0.1-SNAPSHOT.jar --server.port=8082
Since we are developing via an IDE , we can use IDE to add it for us , in STS or Eclipse you can right click on project , go to Run As -> Run Configuration
Inside Run Configuration , open Arguments tab and add –server.port =8082 as shown below.
You can now see our server now starting at 8082.
Now since we have already externalised configuration , we would see some other popular usage of configuration.