mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 01:25:28 +08:00
add 新增 SmsProperties 并注册 sms.enabled 开关默认关闭
This commit is contained in:
parent
18f51687b0
commit
9d9fd42aef
@ -156,6 +156,8 @@ mail:
|
||||
--- # sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商
|
||||
# https://sms4j.com/doc3/ 差异配置文档地址 支持单厂商多配置,可以配置多个同时使用
|
||||
sms:
|
||||
# 是否开启短信功能(默认关,与 mail 保持一致)
|
||||
enabled: false
|
||||
# 配置源类型用于标定配置来源(interface,yaml)
|
||||
config-type: yaml
|
||||
# 用于标定yml中的配置是否开启短信拦截,接口配置不受此限制
|
||||
|
||||
@ -159,6 +159,8 @@ mail:
|
||||
--- # sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商
|
||||
# https://sms4j.com/doc3/ 差异配置文档地址 支持单厂商多配置,可以配置多个同时使用
|
||||
sms:
|
||||
# 是否开启短信功能(默认关,与 mail 保持一致)
|
||||
enabled: false
|
||||
# 配置源类型用于标定配置来源(interface,yaml)
|
||||
config-type: yaml
|
||||
# 用于标定yml中的配置是否开启短信拦截,接口配置不受此限制
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
package org.dromara.test;
|
||||
|
||||
import org.dromara.common.sms.config.SmsAutoConfiguration;
|
||||
import org.dromara.common.sms.config.properties.SmsProperties;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* SmsProperties 绑定 + SmsAutoConfiguration 条件化测试
|
||||
* <p>使用 ApplicationContextRunner,无需启动完整上下文(不需要 MySQL/Redis)
|
||||
*/
|
||||
@DisplayName("SMS 开关配置测试")
|
||||
public class SmsPropertiesTest {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(SmsAutoConfiguration.class));
|
||||
|
||||
@Tag("dev")
|
||||
@DisplayName("sms.enabled=false 时绑定到 SmsProperties.enabled=false")
|
||||
@Test
|
||||
public void shouldBindEnabledFalse() {
|
||||
contextRunner
|
||||
.withPropertyValues("sms.enabled=false")
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(SmsProperties.class);
|
||||
assertThat(context.getBean(SmsProperties.class).getEnabled()).isEqualTo(false);
|
||||
});
|
||||
}
|
||||
|
||||
@Tag("dev")
|
||||
@DisplayName("sms.enabled=true 时绑定到 SmsProperties.enabled=true")
|
||||
@Test
|
||||
public void shouldBindEnabledTrue() {
|
||||
contextRunner
|
||||
.withPropertyValues("sms.enabled=true")
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(SmsProperties.class);
|
||||
assertThat(context.getBean(SmsProperties.class).getEnabled()).isEqualTo(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,12 @@
|
||||
package org.dromara.common.sms.config;
|
||||
|
||||
import org.dromara.common.sms.config.properties.SmsProperties;
|
||||
import org.dromara.common.sms.core.dao.PlusSmsDao;
|
||||
import org.dromara.common.sms.handler.SmsExceptionHandler;
|
||||
import org.dromara.sms4j.api.dao.SmsDao;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
@ -14,6 +16,7 @@ import org.springframework.context.annotation.Primary;
|
||||
* @author Feng
|
||||
*/
|
||||
@AutoConfiguration(after = {RedisAutoConfiguration.class})
|
||||
@EnableConfigurationProperties(SmsProperties.class)
|
||||
public class SmsAutoConfiguration {
|
||||
|
||||
@Primary
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
package org.dromara.common.sms.config.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* 短信配置属性
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "sms")
|
||||
public class SmsProperties {
|
||||
|
||||
/**
|
||||
* 是否开启短信功能(默认关闭,与 mail.enabled 保持一致)
|
||||
*/
|
||||
private Boolean enabled;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user