title: What is the correct way to initialize spring properties (profiles etc.) using java config?
body: <p>I have a file named initParameters.properties which contains a key named spring.profiles.active that's being filtered but that's not enough, because Spring is not aware of this property yet.<br>
  I'm using <strong>AbstractAnnotationConfigDispatcherServletInitializer</strong> as my WebAppInitializer <br> and here is the important part of it:</p>
  
  <pre><code>@Override
  public void onStartup(ServletContext servletContext) throws ServletException {
      super.onStartup(servletContext);
      setInitParameters(servletContext);
  }
  
  @SneakyThrows
  private void setInitParameters(ServletContext servletContext) {
      Properties initParams = new Properties();
      initParams.load(new ClassPathResource("initParameters.properties").getInputStream());
      initParams.stringPropertyNames().stream().forEach(propertyName -&gt; CHOOSE_OPTION_HERE);
  }
  </code></pre>
  
  <p><strong>Option 1:</strong><br></p>
  
  <pre><code>servletContext.setInitParameter(propertyName, initParams.getProperty(propertyName))
  </code></pre>
  
  <p><strong>Option 2:</strong></p>
  
  <pre><code>System.setProperty(propertyName, initParams.getProperty(propertyName))
  </code></pre>
  
  <p>Both ways work, I just don't know what is the difference between them apart from one being a system property and the other an initParameter.<br>
  Ofc, when I set system property -Dspring.profiles.active=someProfile while starting an application, it overrides everything, even the filtering in my .properties file so it's all fine.<br>
  I was looking all over the internet for some explanations, pros/cons but couldn't find anything. <br> Also, if there's a way to notify spring about the property directly from .properties file, I'd also like to know how (aka skipping the setInitParameters part). I think Spring Boot automatically detects it but I'm NOT using it so was wondering if there's something like that in Spring. Thanks for your time.</p>