package demo.helloconfig;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ConfigController {
    @Value("${db.username}")
    private String username;

    @Value("${db.password}")
    private String password;

    @GetMapping(value = "/config1")
    public String getConfig1() {
        return "db.username=" + username+",db.password="+password;
    }

    @Autowired
    private MyProperties myProperties;

    @GetMapping(value = "/config2")
    public String getConfig2() {
      return "db.username=" + myProperties.getUsername()+",db.password="+myProperties.getPassword();
    }
}


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