title: spring boot can not get configuration from application.yml
body: <p>My spring boot application can not get configuration parameters from application.yml file. My main class as following:</p>
  
  <pre><code>@SpringBootApplication(scanBasePackages={"com.test"})
  public class Main {
      @Bean
      public Validator validator(){
          return new  org.springframework.validation.beanvalidation.CustomValidatorBean();
      }
      public static void main(String[] args) throws IOException {
          new SpringApplicationBuilder(Main.class)
          .properties("application.yml")
          .build()
          .run(args);
      }
  }
  </code></pre>
  
  <p>My controller class as following:</p>
  
  <pre><code>@RestController
  @RequestMapping("/test_traffic")
  @Component
  public class AnycastTrafficController {
      @Autowired
      TestService testService;
  
      @GetMapping("/test")
      public Object component() {
           return testService.getTraffic();
      }
  }
  </code></pre>
  
  <p>My Service class as following:</p>
  
  <pre><code>@Service
  public class TestService {
      @Autowired
      TestDao testDao;
  
      public Object getTraffic() {
          testDao.getTraff();
      }
  }
  </code></pre>
  
  <p>My Dao class as following:</p>
  
  <pre><code>@Component
  public class TestDao {
  
      @Autowired
      MyDBConfig mydbConfig;
  
      public DB getMyDBConfig () {
          DB db = new DB(mydbConfig.id, mydbConfig.key);
          return db;
      }
  }
  </code></pre>
  
  <p>My Config class as following:</p>
  
  <pre><code>@Configuration
  @EnableConfigurationProperties
  @ConfigurationProperties(prefix = "mydb")
  public class MyDBConfig {
  
      public String id;
      public String key;
  
      public String getId() {
          return id;
      }
      public void setId(String id) {
          this.id = id;
      }
      public String getKey() {
          return key;
      }
      public void setKey(String key) {
          this.key = key;
      }
  }
  </code></pre>
  
  <p>My application.yml (which located at /src/main/resources)as following:</p>
  
  <pre><code>server:
    port: 8003
    context-path: /
  
  logging:
    level:
      ROOT: INFO
      org.springframework: INFO
      org.springframework.data: INFO
      com.alibaba: INFO
    file: log/
  
  docserver:
    accessKeyId: 1111
    accessKeySecret: 2222
  
  ---
  
  spring:
    profiles: dev
    application:
      name: test-application
  mydb:
    id: 1111111
    key: 2222222
  </code></pre>
  
  <p>But when I started the Main class and request the url, it threw exception as following:</p>
  
  <pre><code>the id should not be empty.
  </code></pre>
  
  <p>that mean my Configuration class didn't get the configure data from yml file, so where I did wrong please. p.s(but the server port 8003 could be found by application). Thanks!</p>