application.yml
配置类
@Component
@ConfigurationProperties(prefix = "system")
public class SystemConfig {private static String name;private String version;private String copyrightYear;private boolean demoEnabled;private static String winUploadPath;private static String otherUploadPath;private static boolean addressEnabled;public static String getName() {return name;}public void setName(String name) {SystemConfig.name = name;}public String getVersion() {return version;}public void setVersion(String version) {this.version = version;}public String getCopyrightYear() {return copyrightYear;}public void setCopyrightYear(String copyrightYear) {this.copyrightYear = copyrightYear;}public boolean isDemoEnabled() {return demoEnabled;}public void setDemoEnabled(boolean demoEnabled) {this.demoEnabled = demoEnabled;}public static String getWinUploadPath() {return winUploadPath;}public static void setWinUploadPath(String winUploadPath) {SystemConfig.winUploadPath = winUploadPath;}public static String getOtherUploadPath() {return otherUploadPath;}public static void setOtherUploadPath(String otherUploadPath) {SystemConfig.otherUploadPath = otherUploadPath;}public static boolean isAddressEnabled() {return addressEnabled;}public void setAddressEnabled(boolean addressEnabled) {SystemConfig.addressEnabled = addressEnabled;}public static String getUploadPath() {OsInfo osInfo = SystemUtil.getOsInfo();if(ObjectUtils.isNotEmpty(osInfo) && osInfo.isWindows()){return getWinUploadPath();}else{return getOtherUploadPath();}}public static String getSystemName() {return getName();}}
name、addressEnabled 以及 winUploadPath、otherUploadPath 都是静态的成员变量,但是他们name、addressEnabled能获取到配置文件的值,winUploadPath、otherUploadPath不可以。
原因就是: winUploadPath、otherUploadPath对应的ser方法也定义为了静态方法。