@value不能直接注入值给静态属性,spring 不允许/不支持把值注入到静态变量中;spring支持set方法注入,我们可以利用非静态setter 方法注入静态变量
@Component public class SendMessageUtil { public static String accessKeyId ; @Value("${accessKeyId}") public void setAccessKeyId(String accessKeyId) { SendMessageUtil.accessKeyId = accessKeyId; } public static String accessKeySecret ; @Value("${accessKeySecret}") public void setAccessKeySecret(String accessKeySecret) { SendMessageUtil.accessKeySecret = accessKeySecret; } }