参考:

https://www.cnblogs.com/bgyb/p/14945489.html

配置文件:yml

#用户信息
userMag:
  userName: "王小波"
  userAge: "21"

工具实体类:UserConstant

@Component
public class UserConstant {

    private static String userName;

    @Value("${userMag.userName}")
    private void setUserName(String userName) {//注入值
        UserConstant.userName = userName;
    }

    public static String getUserName() {//获取值
        return userName;
    }

    private static String userAge;

    @Value("${userMag.userAge}")
    private void setUserAge(String userAge) {//注入值
        UserConstant.userAge = userAge;
    }

    public static String getUserAge() {//获取值
        return userAge;
    }
}