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

197
Views
Loading Java Properties Files by Profile

I want to load Properties Files in Java code. But I use profile to config -Dspring.profiles.active=local or dev... How to load properties files by profile Something like this:

classpath:${spring.profiles.active}/test.properties

How to do that in Java code ? I did as below, but get null.

Properties prop = new Properties();
InputStream iStream = Helper.class.getClassLoader().getResourceAsStream("test.properties");
    try {
        prop.load(iStream);
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    } finally {
        try {
            iStream.close();
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        }
    }
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

This is some working code for us:

String activeProfile = System.getProperty("spring.profiles.active");
InputStream workSpacesFIS = this.getClass().getClassLoader()
        .getResourceAsStream(activeProfile + "/customers.txt");
if (workSpacesFIS != null) { ...
about 4 years ago · Santiago Trujillo Report

0

Loading Java Properties Files by Profile

public Properties getProp() throws IOException {
        final Properties prop = new Properties();
        prop.load(TestService.class.getResourceAsStream("/application.properties"));
        String activeProfile = prop.getProperty("spring.profiles.active");
        prop.load(TestService.class.getResourceAsStream("/application-"+activeProfile+".properties"));
        return prop;

    }
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!