package demo.helloconfig;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.util.concurrent.TimeUnit;

@SpringBootApplication

public class HelloConfigApplication {

    public static void main(String[] args) throws Exception{

        ConfigurableApplicationContext applicationContext=SpringApplication.run(HelloConfigApplication.class, args);
        while(true) {
            String username = applicationContext.getEnvironment().getProperty("db.username");
            String password = applicationContext.getEnvironment().getProperty("db.password");
            System.out.println("db.username=" + username + ",db.password=" + password);
            TimeUnit.SECONDS.sleep(1);     //睡眠1秒
        }
    }

}


/*********************************************************
 * 作者：孙卫琴                                   
 * 来源：《Spring Cloud Alibaba微服务开发零基础入门到实战》源代码  
 * 技术支持网址：www.javathinker.net/alibaba                    
 *********************************************************/
