mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-19 01:48:47 +08:00
update 条件化 SmsAutoConfiguration 的 SmsDao/异常处理器 Bean
This commit is contained in:
parent
9d9fd42aef
commit
7865f5210e
@ -2,6 +2,8 @@ package org.dromara.test;
|
|||||||
|
|
||||||
import org.dromara.common.sms.config.SmsAutoConfiguration;
|
import org.dromara.common.sms.config.SmsAutoConfiguration;
|
||||||
import org.dromara.common.sms.config.properties.SmsProperties;
|
import org.dromara.common.sms.config.properties.SmsProperties;
|
||||||
|
import org.dromara.common.sms.handler.SmsExceptionHandler;
|
||||||
|
import org.dromara.sms4j.api.dao.SmsDao;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Tag;
|
import org.junit.jupiter.api.Tag;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -43,4 +45,28 @@ public class SmsPropertiesTest {
|
|||||||
assertThat(context.getBean(SmsProperties.class).getEnabled()).isEqualTo(true);
|
assertThat(context.getBean(SmsProperties.class).getEnabled()).isEqualTo(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Tag("dev")
|
||||||
|
@DisplayName("sms.enabled=false 时不创建 PlusSmsDao / SmsExceptionHandler")
|
||||||
|
@Test
|
||||||
|
public void shouldNotCreateSmsBeansWhenDisabled() {
|
||||||
|
contextRunner
|
||||||
|
.withPropertyValues("sms.enabled=false")
|
||||||
|
.run(context -> {
|
||||||
|
assertThat(context).doesNotHaveBean(SmsDao.class);
|
||||||
|
assertThat(context).doesNotHaveBean(SmsExceptionHandler.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tag("dev")
|
||||||
|
@DisplayName("sms.enabled=true 时创建 PlusSmsDao / SmsExceptionHandler")
|
||||||
|
@Test
|
||||||
|
public void shouldCreateSmsBeansWhenEnabled() {
|
||||||
|
contextRunner
|
||||||
|
.withPropertyValues("sms.enabled=true")
|
||||||
|
.run(context -> {
|
||||||
|
assertThat(context).hasSingleBean(SmsDao.class);
|
||||||
|
assertThat(context).hasSingleBean(SmsExceptionHandler.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import org.dromara.common.sms.core.dao.PlusSmsDao;
|
|||||||
import org.dromara.common.sms.handler.SmsExceptionHandler;
|
import org.dromara.common.sms.handler.SmsExceptionHandler;
|
||||||
import org.dromara.sms4j.api.dao.SmsDao;
|
import org.dromara.sms4j.api.dao.SmsDao;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@ -21,6 +22,7 @@ public class SmsAutoConfiguration {
|
|||||||
|
|
||||||
@Primary
|
@Primary
|
||||||
@Bean
|
@Bean
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "enabled", havingValue = "true")
|
||||||
public SmsDao smsDao() {
|
public SmsDao smsDao() {
|
||||||
return new PlusSmsDao();
|
return new PlusSmsDao();
|
||||||
}
|
}
|
||||||
@ -29,6 +31,7 @@ public class SmsAutoConfiguration {
|
|||||||
* 异常处理器
|
* 异常处理器
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "enabled", havingValue = "true")
|
||||||
public SmsExceptionHandler smsExceptionHandler() {
|
public SmsExceptionHandler smsExceptionHandler() {
|
||||||
return new SmsExceptionHandler();
|
return new SmsExceptionHandler();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user