Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
Loading additional spring profiles from java config

Is there any possibility to load aditional spring profiles from java config?

I know that I can use -Dspring.profile.active argument and also add profiles to spring.profiles.include in application.properties.

What I need is to be able to activate profiles from java config. I've created PropertyPlaceholderConfigurer, where I'm adding some custom property files, which also contains property spring.profiles.include, all properties are load and it works ok, but spring doesn't activate any profiles which are inclded using this property.

@Bean
public static PropertyPlaceholderConfigurer ppc() throws IOException {
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    ppc.setLocations(new ClassPathResource("properties/" + property + ".properties"));
    ppc.setIgnoreUnresolvablePlaceholders(true);
    return ppc;
}
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The active spring profiles are defined in properties via the following configuration: spring.profiles.active:.

You should list in all the files that you import the profiles that they activate via the above configuration key.

EDIT

First, as per the official documentation the configuration spring.profiles.include is more suitable for unconditionally adding active profiles.

Second, I can assume that PropertyPlaceholderConfigurer is not suitable for what you want to achieve. The official documentation lists the ways you can Externalize Configuration. You can try to use @PropertySource:

@PropertySources({
        @PropertySource(value = "classpath:application.properties"),
        @PropertySource(value = "classpath:other.properties", ignoreResourceNotFound = true)
})
public class Application {
       ...
    }
}

Additionally, you can try to list the other properties files in property spring.config.location inside application.properties as described here.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!