title: Spring boot unable to read from profile specific yaml file
body: <p>I was playing around with spring boot and attempted to create a profile specific configuration file. I called it <code>application-local.yml</code>.</p>
  
  <p>And added:</p>
  
  <pre><code>spring:
   profiles:
    active: local
  
   mysql:
    db:
     url: jdbc:mysql://localhost:3306/db?serverTimezone=UTC
     driverClassName: com.mysql.jdbc.Driver
     username: root
     password:
  
  hibernate:
   dialect: org.hibernate.dialect.MySQL5Dialect
   show_sql: false
  
  server:
   port: 8080
  </code></pre>
  
  <p>And in my DatabaseConfig.java file I attempt to read from <code>application-local.yml</code> and configure the database:</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  public class DatabaseConfig {
  
      @Value("${spring.mysql.db.url}")
      private String url;
  
      @Value("${spring.mysql.db.username}")
      private String userName;
  
      @Value("${spring.mysql.db.password}")
      private String password;
  
      @Value("${spring.mysql.db.driverClassName}")
      private String driverClassName;
  
      //hibernate
      @Value("${hibernate.dialect}")
      private String hibernateDialect;
  
      @Value("${hibernate.show_sql}")
      private String hibernateShowSql;
  
      @Bean
      public DataSource dataSource() {
          BasicDataSource dataSource = new BasicDataSource();
          dataSource.setUrl(url);
          dataSource.setDriverClassName(driverClassName);
          dataSource.setUsername(userName);
          dataSource.setPassword(password);
          return dataSource;
      }
  
      @Bean(name="entityManagerFactory")
      public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
          LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean =
                  new LocalContainerEntityManagerFactoryBean();
          localContainerEntityManagerFactoryBean.setDataSource(dataSource());
          localContainerEntityManagerFactoryBean.setPackagesToScan("xxxx");
  
          JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
          localContainerEntityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter);
          localContainerEntityManagerFactoryBean.setJpaProperties(hibernateProperties());
          return localContainerEntityManagerFactoryBean;
      }
  
      @Bean
      public PlatformTransactionManager platformTransactionManager() {
          JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
          jpaTransactionManager.setEntityManagerFactory(entityManagerFactoryBean().getObject());
          return jpaTransactionManager;
      }
  
      private Properties hibernateProperties() {
          Properties properties = new Properties();
          properties.put("hibernate.dialect", hibernateDialect);
          properties.put("hibernate.show_sql", hibernateShowSql);
          return properties;
      }
  }
  </code></pre>
  
  <p>Now I get the error it's unable to </p>
  
  <blockquote>
    <p>Error creating bean with name 'databaseConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.mysql.db.url' in value "${spring.mysql.db.url}" </p>
  </blockquote>
  
  <p>but when I rename my property file to <code>application.yml</code>. It works perfectly fine.</p>
  
  <p>I also attempted to run from the terminal using gradle command: <code>./gradlew -Dspring.profiles.active=local bootRun</code> but I get the same error. It only works when I refactor the YAML file to <code>application.yml</code>. What am I doing wrong? I intend to have 3 profiles such as local, dev and prod. </p>