修复:短信发送插件未找到抛异常问题

This commit is contained in:
ruying408
2024-11-13 21:45:22 +08:00
parent 177c3540df
commit d9372e94cf
3 changed files with 19 additions and 6 deletions

View File

@@ -328,9 +328,16 @@ public class CoolPluginService {
}
/**
* 获取插件实例对象
* 获取插件实例对象,插件未找到,抛出异常
*/
public Object getInstance(String key) {
return dynamicJarLoaderService.getBeanInstance(key);
}
/**
* 获取插件实例对象,插件未找到,不抛出异常
*/
public Object getInstanceWithoutCheck(String key) {
return dynamicJarLoaderService.getInstanceWithoutCheck(key);
}
}

View File

@@ -166,17 +166,23 @@ public class DynamicJarLoaderService {
}
/**
* 获取插件实例对象
* 获取插件实例对象,插件未找到,抛出异常
*/
public Object getBeanInstance(String key) {
Object instance = getInstanceWithoutCheck(key);
CoolPreconditions.checkEmpty(instance,"插件 {} 未找到", key);
return instance;
}
/**
* 获取插件实例对象,插件未找到,不抛出异常
*/
public Object getInstanceWithoutCheck(String key) {
CoolPreconditions.checkEmpty(key, "插件key is null");
if (pluginMap.containsKey(key)) {
return pluginMap.get(key);
}
CoolPreconditions.alwaysThrow("插件 {} 未找到", key);
return null;
}
/**
* 获取自定义类加载器
*/

View File

@@ -76,10 +76,10 @@ public class UserSmsUtil {
Map<String, Object> params = new HashMap<>();
params.put("code", code);
// 插件key sms-tx、sms-ali哪个实例存在就调用哪个
if (coolPluginService.getInstance("sms-tx") != null) {
if (coolPluginService.getInstanceWithoutCheck("sms-tx") != null) {
// 调用腾讯短信插件
CoolPluginInvokers.invoke("sms-tx", "send", phones, params);
} else if (coolPluginService.getInstance("sms-ali") != null) {
} else if (coolPluginService.getInstanceWithoutCheck("sms-ali") != null) {
// 调用阿里短信插件
CoolPluginInvokers.invoke("sms-ali", "send", phones, params);
} else {