Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot adding another properties file to the environment

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

like image 466
starcraftOnCrack Avatar asked Nov 14 '14 17:11

starcraftOnCrack


People also ask

Can we create multiple properties file in spring boot?

We can create any number of application. properties file according to our needs and use them in our spring boot application.

How import multiple properties in spring boot?

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.

How do I set environment specific properties in spring boot?

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.

How do I set different application properties in spring boot?

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.


1 Answers

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{

}
like image 197
jayb0b Avatar answered Sep 20 '22 00:09

jayb0b