Spring Boot :Profile Specific Properties and Placeholders in properties
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...
Profile Specific Properties
Spring provides profiles for environment based properties. For example Database related properties will change for Development , QA and Production environment. For such cases we can create property file like
application-{profile}.properties
Like application-dev.properties , application-qa.properties or application-prod.properties .By default , if not specified profile is “default”, You can see this happening in logs as well. Below is the screenshot of same :
Consider a property like app.name defiled in application.properties and as well as application-{profile}.properties like application-dev.properties. If the profile is set to dev , the value for app.name in.properties will be considered. It will override the default one.
We will see profile in details in next chapter.
Placeholder in properties
Placeholders could be of great use when defining any properties file specially a long one with references from other properties. For example , see below properties
app.name=User Application
app.version= 1.0.0
app.description = ${app.name} - ${app.version} is an application to store user details.
If we add above properties in application.properties file , and try to fetch app.description property, It will refer app.name and app.version to create value for app.description. Let’s test it
We will add a Simple request mapping in our common controller and return these values via a map.
@Autowired
private Environment env;
@RequestMapping("app-info")
protected Map<String,String>appInfo(){
Map<String,String>appInfo= new LinkedHashMap<String,String>();
appInfo.put("name", env.getProperty("app.name"));
appInfo.put("version", env.getProperty("app.version"));
appInfo.put("description", env.getProperty("app.description"));
return appInfo;
}
Now if we hit the URL http://localhost:8081/v1/app-info , we will get following response validation that placeholders are working. (It can be noted that we have removed command line parameter of –server.port, that’s why it is running on 8081 picking from properties file )
{
"name": "User Application",
"version": "1.0.0",
"description": "User Application - 1.0.0 is an application to store user details."
}
Here name and versions are replaced in description.