1.springboot 读取配置文件yarn
1.1 准备配置文件yaml
在main目录下新建resources目录,并设置为Root Resources,新建文件application.yaml
server:
ip: 10.1.0.6
hostname: hadoop-bd1
admin: zhangsan
yaml是替代传统的xx.properties文件,是一种方便的定义层次配置数据的格式
1.2 创建配置类,通过@Value来注入值
1.2.1 @Value(“xxx”)直接指定值
package com.mp.prj.domain;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class Server01 {
@Value("10.1.0.1")
private String ip;
@Value("hadoop-bd1")
private String hostname;
@Value("1")
private int admin;
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getHostname() {
return hostname;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public int getAdmin() {
return admin;
}
public void setAdmin(int admin) {
this.admin = admin;
}
@Override
public String toString() {
return "Server01{" +
"ip='" + ip + '\'' +
", hostname='" + hostname + '\'' +
",