0

I have a lot of profiles, I want to put it to /profiles folder, I do not want to put it to classpath:/,classpath:/config/,file:./,file:./config/, I saw the Class ConfigFileApplicationListener, Is there any other way?

Peter
  • 3
  • 1
  • 1
    you need to be more specific. What does your project setup look like. Where is the profiles folder? How does the application find that folder when run? Are you packaging the config files with your app? Do you want to provide them separately? Do you want them on the classpath? – pandaadb Jan 11 '18 at 11:49

1 Answers1

0

Hard to tell exactly what you are asking, but it sounds like you want to put your profile-specific properties files in a /profiles directory, rather than one of the default search locations.

In the ConfigFileApplicationListener, you can specify /profiles using setSearchLocations()

Alternative search locations and names can be specified using setSearchLocations(String) and setSearchNames(String).

From the Javadocs for ConfigFileApplicationListener.setSearchLocations():

Set the search locations that will be considered as a comma-separated list. Each search location should be a directory path (ending in "/") and it will be prefixed by the file names constructed from setSearchNames(String) search names and profiles (if any) plus file extensions supported by the properties loaders. Locations are considered in the order specified, with later items taking precedence (like a map merge).

Add the custom ConfigFileApplicationListener to the SpringApplication via the addListeners() method before calling run().

Alternative Method

As a somewhat easier workaround, I find @masted's solution here this method to be much easier. The only downside is you need to add an environment variable,

-Dext.properties.dir=classpath:/profiles/

followed by whatever environment you want to point to.

bdetweiler
  • 1,544
  • 1
  • 16
  • 27
  • Edit your question and add some more details (stacktrace, reproducible example code, etc). Otherwise it's just a guessing game. – bdetweiler Jan 25 '18 at 13:18