SpringBoot如何优雅的将静态资源配置注入到工具类中

资源注入类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@Configuration
@ConfigurationProperties(locations = "classpath:/config/qcloud.properties", ignoreUnknownFields = true, prefix = "qcloud")
public class QCloudProperties {
public static class properties {
}

private String appid;
private String secretId;
private String secretKey;
private String bucketName;
private Strign bucketLocation;

public QCloudProperties() {
}
}

工具类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Component
public class QCloudFileUtils {
@Resource
private QCloudProperties qCloudPropertiesAutowired;

private static QCloudProperties qCloudProperties;

@PostConstruct
public void init() {
qCloudProperties = this.qCloudPropertiesAutowired;
}

public static boolean upload() {
String appid = qCloudProperties.getAppid();
return false;
}
}

https://my.oschina.net/vright/blog/826184