Application Properties in Spring boot enable different configurations for different environments. Spring Boot's main advantage over the standard Spring framework is Lesser-Configuration. Spring Boot's convention over configuration is very well applied to application properties files. We, at Oodles, as an Artificial Intelligence Development Company, highlight the best practices while setting up application properties in the Spring boot environment.
Spring Boot provides a default "application.properties" file and it's autodetected without any extra configurations. We just need to place "application.properties" file inside the "src/main/resources" directory. In your properties file, there is no limit to add properties. You may add as many properties as per your requirement.
In multiple environments, we need a separate properties file for each environment.
Let’s assume you have two environments, development and production. So you need two different application.properties like “application-development.properties” and “application-production.properties”
We can specify in our default "application.properties" which properties should Spring Boot application while starting the application.
On application startup, the active profile will be picked and properties of the active profile will be given priority.
The most important point to remember, that default "application.properties" file will still be loaded. But when there is any property collision (a property specified in default application.properties and the same property is specified in the environment-specific properties file) in this situation properties of environment-specific property file will be given priority and loaded.
Identify which properties are common and you don't want different values for those properties in environments. Common properties MUST be kept ONLY in the default application.properties file.
@Value Annotation Usage
@Value annotation used to read environment or application property's value in Java code. Below is the syntax which reads the value of a property.
As an alternate to application.properties file, Spring Boot also provides configuration with YAML File. YAML file serves the same purpose as "application.properties" it's just that there is a difference in systax/format. YAML also should be kept in "src/main/resources" directory.
YAML Sample File
Spring framework allows for the easy and versatile development of web-based applications. We at Oodles AI are a team of developers with experiential knowledge in working with Spring, Java, Apache, React, Flutter, and other latest frameworks. Under AI, our capabilities include intelligent chatbot development, recommendation systems, computer vision applications, and predictive analytics services.