From ab45404634a7d1aa0f62bd730d3a76d0e4150378 Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Sun, 22 Jul 2018 15:11:49 +0800 Subject: [PATCH] =?UTF-8?q?chore[litemall-core]:=20=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=87=87=E7=94=A8lazy=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../litemall/core/storage/StorageService.java | 11 ++++------- .../config/StorageAutoConfiguration.java | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java index 0fc71aac..29ca050c 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/StorageService.java @@ -4,7 +4,6 @@ import org.springframework.core.io.Resource; import org.springframework.web.multipart.MultipartFile; import java.nio.file.Path; -import java.util.Map; import java.util.stream.Stream; /** @@ -13,7 +12,6 @@ import java.util.stream.Stream; public class StorageService { private String active; private Storage storage; - private Map supportedStorage; public String getActive() { return active; @@ -21,15 +19,14 @@ public class StorageService { public void setActive(String active) { this.active = active; - this.storage = this.supportedStorage.get(active); } - public Map getSupportedStorage() { - return supportedStorage; + public Storage getStorage() { + return storage; } - public void setSupportedStorage(Map supportedStorage) { - this.supportedStorage = supportedStorage; + public void setStorage(Storage storage) { + this.storage = storage; } /** diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageAutoConfiguration.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageAutoConfiguration.java index 0b8e9187..62fe0920 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageAutoConfiguration.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/config/StorageAutoConfiguration.java @@ -22,12 +22,21 @@ public class StorageAutoConfiguration { public StorageService storageService() { StorageService storageService = new StorageService(); Map supportedStorage = new HashMap(3); - supportedStorage.put("local", localStorage()); - supportedStorage.put("aliyun", aliyunStorage()); - supportedStorage.put("tencent", tencentStorage()); - storageService.setSupportedStorage(supportedStorage); String active = this.properties.getActive(); storageService.setActive(active); + if(active.equals("local")){ + storageService.setStorage(localStorage()); + } + else if(active.equals("aliyun")){ + storageService.setStorage(aliyunStorage()); + } + else if(active.equals("tencent")){ + storageService.setStorage(tencentStorage()); + } + else{ + throw new RuntimeException("当前存储模式 " + active + " 不支持"); + } + return storageService; }