yml
system:
version: 1.0.0
key: AAAAVCC
JAVA配置类
package com.my.test.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
public class YmlConstant {
private static String KEY;
public static String getKEY() {
return KEY;
}
@Value("${system.key:'1234'}")
public void setKEY(String KEY) {
YmlConstant.KEY = KEY;
}
}
调用
System.out.println(YmlConstant.getKEY());