可应用于static代码块内读取application.yml配置内容
package com.ahzx.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Component
//@ConfigurationProperties(prefix = "gen")
@PropertySource(value = {"classpath:application.yml"})
public class ApplicationConfig {
private static String aqPrivateKey;
public static String getAqPrivateKey() {
return aqPrivateKey;
}
@Value("${aqPrivateKey}")
public void setAqPrivateKey(String aqPrivateKey) {
ApplicationConfig.aqPrivateKey = aqPrivateKey;
}
}