@ConfigurationProperties给自定义的属性赋值不成功的原因
YML配置文件中的内容
aliyun:
oss:
file:
endpoint: oss-cn-hangzhou
keyid: 7878
keysecret: 43566768
bucketname: a great
读取配置文件的类:
@Component
@ConfigurationProperties(prefix = "aliyun.oss.file")
public class ConstantYmlUtils implements InitializingBean {
// @Value("${aliyun.oss.file.endpoint}")
private String endpoint;
// @Value("${aliyun.oss.file.keyid}")
private String keyid;
// @Value("${aliyun.oss.file.keysecret}")
private String keysecret;
// @Value("${aliyun.oss.file.bucketname}")
private String bucketname;
public static String OSSENDPOINT;
public static String OSSKEYID;
public static String OSSKEYSECRET;
public static String OSSBUCKETNAME;
@Override
public void afterPropertiesSet() throws Exception {
OSSENDPOINT = endpoint;
OSSKEYID = keyid;
OSSKEYSECRET = keysecret;
OSSBUCKETNAME = bucketname;
}
}
测试过程中并没有读取成功,而我配置的属性值和前缀都和YML文件中的信息匹配
未成功匹配的原因:没有给属性值加添get和set方法,添加后,复制成功