title: Spring Boot 2 : How to load each application.yml files of different modules into a given web or batch runner
body: <p>I create a Spring Boot Application, and I'm wondering if it is possible to load upmteens application.yml files of different modules.</p>
  
  <p>I have this structure :</p>
  
  <pre><code>myProject
  |__ moduleCommons
  |   |__ application.yml
  |__ moduleWeb
  |   |__ application.yml
  |   |__ MyProjectWebApplication.java
  |__ moduleBatch
      |__ application.yml
      |__ MyProjectBatchApplication.java
  </code></pre>
  
  <p>To launch the Spring Boot application of web module, I run the MyProjectWebApplication.java.</p>
  
  <p>To launch a Spring Batch of batch module, I run the MyProjectBatchApplication.java.</p>
  
  <p>Both of them need some commons properties, which are set in application.yml file of commons module (like database configuration, directory paths for upload files, etc.).
  And some others properties are specific to each module, so set in application.yml file of web module (like servlet context path, jwt settings) or batch module (like mailer settings).</p>
  
  <p>And, for example, MyProjectWebApplication class into which i would like to load web and commons application.yml files :</p>
  
  <pre><code>package com.myProject.web;
  
  @SpringBootApplication(
          scanBasePackages = {"com.myProject.web", "com.myProject.commons"},
          exclude = {DataSourceAutoConfiguration.class, LiquibaseAutoConfiguration.class}
  )
  @EnableJpaRepositories(
          basePackages = "com.myProject.commons.datasources.defaut.repository",
          repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class
  )
  @ContextConfiguration(classes = {MyProjectDbConfig.class})
  public class MyProjectWebApplication extends SpringBootServletInitializer {
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(MyProjectWebApplication.class);
      }
  
      public static void main(String[] args) {
          SpringApplication.run(MyProjectWebApplication.class, args);
      }
  }
  </code></pre>
  
  <p>But it seems I load only web module application.yml file with this configuration...</p>
  
  <p>Help ! :)</p>