title: SpringBoot - Order of Bean creation and PostConstruct initialization
body: <p>I have a maven multimodule SpringBoot web application. I have a submodule, called <em>config-module</em> which has a configuration class:</p>
  
  <pre><code>@Configuration
  public class PropertiesConfig {
  
      @Bean
      public YamlPropertiesFactoryBean errorPropertiesFromYamlFile() {
          final YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
          yaml.setResources(new ClassPathResource("errorMessages.yml"));
          return yaml;
      }
  
  }
  </code></pre>
  
  <p>I have a <em>web-app-module</em> maven module, which has the previous <em>config-module</em> as a dependency, and as an imported spring application.</p>
  
  <p>In this main module, I also have a configuration class which loads new properties:</p>
  
  <pre><code>@Configuration
  public class WebPropertiesConfig {
  
      @Bean
      public YamlPropertiesFactoryBean webPropertiesFromYamlFile() {
          final YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
          yaml.setResources(new ClassPathResource("webProperties.yml"));
          return yaml;
      }
  
  }
  </code></pre>
  
  <p>And in this module I also have a class like this:</p>
  
  <pre><code>@Component
  @ConfigurationProperties(prefix = "webpart")
  public class ConfigPropertiesMapper {
  
      @PostConstruct
      public void init() {
          //do something here
      }
  
  }
  </code></pre>
  
  <p>And I don't know where it comes from, but the actual order of initialization is this (I checked it within debug mode):</p>
  
  <ol>
  <li><code>PropertiesConfig.errorPropertiesFromYamlFile()</code> bean creation from
  config-module </li>
  <li><code>ConfigPropertiesMapper.init()</code> PostConstruct initialization from
  web-app-module</li>
  <li><code>WebPropertiesConfig.webPropertiesFromYamlFile()</code> bean creation from
  web-app-module</li>
  </ol>
  
  <p>Why is that? And how could I set the order to this?:</p>
  
  <ol>
  <li><code>PropertiesConfig.errorPropertiesFromYamlFile()</code></li>
  <li><code>WebPropertiesConfig.webPropertiesFromYamlFile()</code></li>
  <li><code>ConfigPropertiesMapper.init()</code></li>
  </ol>
  
  <p>I tried with the <code>@Order</code>, <code>@Qualifier</code>, <code>@Primary</code> annotations, but I could not solve this.</p>
  
  <p>I know one more annotation: <code>@DependsOn</code>. But honestly, I don't want to use it, because then I need to add this annotation to every methods which has <code>@PostConstruct</code> on it.</p>