title: how to call a method after Environment object initialized in Spring and java?
body: <p>i have a class which contains reading a property file through spring.</p>
  
  <pre><code>Property file name sample.properties:
    Properties contains:
           a=A1
           b=B1
           etc.,
  </code></pre>
  
  <p>So i am reading easily through env variable. 
  So i need this thing two purpose , One is Key Value and second is Value as key , key as Value(vice-versa)
  Hence, i added a method to put key as vaule and value as key in Map.
  The problem, its not putting values in map, so everything null. i am guessing @postConstruct is may be problem?
  and PropLoaderUtils class nowhere added in bean file. But howvever, i am getting value in env .</p>
  
  <pre><code>@Component
  @Configuration
  @PropertySource(name = "props", value = {
          "classpath:config/sample.properties"
          })
  public class PropLoaderUtils {
      @Autowired
      private Environment env;
  
      private Map&lt;String, String&gt; valueAsKeyMap = new HashMap&lt;String, String&gt;();
  
  
      @PostConstruct
      private void setPropertyKeys() {
          Iterator&lt;?&gt; itr = ((AbstractEnvironment) env).getPropertySources().iterator();
          Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
          while (itr.hasNext()) {
              PropertySource propertySource = (PropertySource) itr.next();
              if (propertySource instanceof MapPropertySource) {
                  map.putAll(((MapPropertySource) propertySource).getSource());
              }
          }
  
          for (Entry&lt;String, Object&gt; entry : map.entrySet()) {
              valueAsKeyMap.put(entry.getValue().toString(),entry.getKey());
  
          }
      }
      public String getProperty(String key) {
          String prop = env.getProperty(key);
          return prop;
      }
  
      public String getPropertyKeyAsValues(String value) {
          return valueAsKeyMap.getProperty(value);
  
      }
  
  
  }
  </code></pre>