I was wondering if it was possible to add another properties file to the environment path besides just the application.properties file. If so how do you specify the new path? So you can access the properties using the Autowired Environment variable. Currently in my java project the default properties file application.properties have the path /soctrav/src.main.resources/application.properties
We can create any number of application. properties file according to our needs and use them in our spring boot application.
To add different files you can use the spring. config. location properties which takes a comma separated list of property files or file location (directories). The one above will add a directory which will be consulted for application.
Environment-Specific Properties File. If we need to target different environments, there's a built-in mechanism for that in Boot. We can simply define an application-environment. properties file in the src/main/resources directory, and then set a Spring profile with the same environment name.
Spring Boot Framework comes with a built-in mechanism for application configuration using a file called application. properties. It is located inside the src/main/resources folder, as shown in the following figure. Spring Boot provides various properties that can be configured in the application.
If you want to do it without command line parameters, this will do the trick.
@SpringBootApplication
@PropertySources({
@PropertySource("classpath:application.properties"),
@PropertySource("classpath:anotherbunchof.properties")
})
public class YourApplication{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With