title: load properties file and access later from another class - spring
body: <p>I'm loading a properties file in java in the following way in class A (loadConfig is called as soon as the program is executed and it is executed without any problem, what's more, the register of showing configProp.getAttribute(&quot;home&quot;) returns me the correct value of the configuration file:</p>
  <pre><code>public class config {
    private static Properties properties; // this file contains the name of the wfile.properties and route that I want to 'save' in configProp to access later
  
    @Autowired
    public final Properties configProp = new Properties();
    
    public Properties getProperties() {
       return configProp;
    }
  
    public void loadconfig() {
          File wFile = new File(properties.getProperty(&quot;wfile.properties&quot;);
          try (FileInputStream fis = new FileInputStream(wFile)) {
              configProp.load(fis); // this is loading without any problem
              
              getLogger(HASH).info(&quot;***FILE LOADED configProp*** ==== &quot; + configProp); // PRINTS THE CORRECT FILE AND ALL OF THE VALUES
              getLogger(HASH).info(&quot;***FILE LOADED configProp*** ==== &quot; + configProp.getAttribute(&quot;home&quot;); // PRINTS THE CORRECT VALUE FROM THE PROPERTIES FILE
              fis.close();
            } catch (IOException e) {
                getLogger(HASH).error(&quot;Error loading configProp properties file&quot;, e);
              throw new RuntimeException(e);
            } 
    }
    
  </code></pre>
  <p>The problem is, that I need to access these attributes from another class later, I am doing it in the following way:</p>
  <pre><code>public class classB {
  
      public static void main(String[] args) {
  
         Config config = new Config();
         getLogger(HASH).info(config.getProperties().getProperty(&quot;home&quot;));  // RETURNS NULL I DONT KNOW WHY
         String home1 = config.getProperties().getProperty(&quot;home&quot;);  // RETURNS NULL I DONT KNOW WHY
     }
  </code></pre>
  <p>I'm using spring and that's why I put @autowired in the variable, but it still returns null.
  I hope I have explained it clearly, I have tried several things like putting the load in the constructor but it made a loop.</p>
  <p>Thank you so much.</p>
  <p>Edit:
  I also tried loading the file like:</p>
  <pre><code>  final ClassLoader loader = getClass().getClassLoader();
    try(InputStream config = loader.getResourceAsStream(properties.getProperty(wfile.properties))){
        configProp.load(config);
    } catch(IOException e){
        throw new RuntimeException(e);
    }
  </code></pre>