package com.gdrcu.ifbp.utils.oss.util; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; /** * @program: ifbp * @description: OSS配置类 * @author: CRong.L * @create: 2019-03-07 10:03 **/ @Configuration public class OssConfig { private static String endpoint; private static String accessKeyId; private static String accessKeySecret; private static String bucketName; @Autowired public OssConfig(@Value("${oss.endpoint}") String endpoint , @Value("${oss.accessKeyId}")String accessKeyId , @Value("${oss.accessKeySecret}")String accessKeySecret, @Value("${oss.bucketName}")String bucketName ) { this.endpoint = endpoint; this.accessKeyId = accessKeyId; this.accessKeySecret = accessKeySecret; this.bucketName = bucketName; } public static String getBucketName() { return bucketName; } public static void setBucketName(String bucketName) { OssConfig.bucketName = bucketName; } public static String getEndpoint() { return endpoint; } public static void setEndpoint(String endpoint) { OssConfig.endpoint = endpoint; } public static String getAccessKeyId() { return accessKeyId; } public static void setAccessKeyId(String accessKeyId) { OssConfig.accessKeyId = accessKeyId; } public static String getAccessKeySecret() { return accessKeySecret; } public static void setAccessKeySecret(String accessKeySecret) { OssConfig.accessKeySecret = accessKeySecret; } }
非 @Controller 注解,可以先使用 @Value 把 需要注入的参数 通过构造方法注入 ,然后通过 静态方式获取