SpringBoot 获取 Yml 配置 信息 Environment

SpringBoot 获取 Yml 配置 信息 Environment,第1张

yml 或者 .application 文件

it:
  id: 1
  name: 祝艳
  component:
  	age: 24
  	city: 长沙

java

@slf4j
public testController{
	@Autowired
	@Lazy
	private Environment environment;

	@GetMapper(value = "/getConfig")
	public String getConfig(){
		String id = environment.getProperty("it.id");
		String name = environment.getProperty("it.name ");
		String age = environment.getProperty("it.component.age");
		String city= environment.getProperty("it.component.city");

		log.info("id: [{}], name: [{}], age: [{}], city: [{}]", id, name, age, city)
	}
}




欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/722009.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存