|
@@ -0,0 +1,31 @@
|
|
|
|
+package com.fdkankan.fyun.oss.config;
|
|
|
|
+
|
|
|
|
+import com.aliyun.oss.OSS;
|
|
|
|
+import com.aliyun.oss.OSSClientBuilder;
|
|
|
|
+import com.fdkankan.fyun.config.FYunFileConfig;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
|
+import org.springframework.context.annotation.Scope;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+public class OssConfig {
|
|
|
|
+
|
|
|
|
+ @Value("${fyun.oss.endPoint}")
|
|
|
|
+ private String point;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private FYunFileConfig fYunFileConfig;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 配置多实例,且使用时候要手动shutdown,否则会造成内存溢出
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Bean
|
|
|
|
+ @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
|
|
+ public OSS ossClient(){
|
|
|
|
+ return new OSSClientBuilder().build(point, fYunFileConfig.getKey(), fYunFileConfig.getSecret());
|
|
|
|
+ }
|
|
|
|
+}
|