mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-06 17:08:40 +08:00
重命名springUtil为SmsSpringUtil防止bean冲突
This commit is contained in:
parent
4ac277ed90
commit
cf968cd6d0
@ -1,13 +1,13 @@
|
||||
package org.dromara.sms4j.api.universal;
|
||||
|
||||
/**
|
||||
* RedisUtil
|
||||
* SmsRedisUtil
|
||||
* <p> redis工具接口,用户可自主实现以更换redis的来源
|
||||
*@since 2.2.0
|
||||
* @author :Wind
|
||||
* 2023/6/6 22:21
|
||||
**/
|
||||
public interface RedisUtil {
|
||||
public interface SmsRedisUtil {
|
||||
|
||||
/**
|
||||
* setOrTime
|
||||
@ -2,7 +2,7 @@ package org.dromara.sms4j.solon.aop;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.smsProxy.RestrictedProcess;
|
||||
import org.dromara.sms4j.api.universal.RedisUtil;
|
||||
import org.dromara.sms4j.api.universal.SmsRedisUtil;
|
||||
import org.dromara.sms4j.comm.config.SmsConfig;
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
import org.dromara.sms4j.comm.utils.SmsUtil;
|
||||
@ -11,13 +11,13 @@ import org.noear.solon.core.AopContext;
|
||||
@Slf4j
|
||||
public class SolonRestrictedProcess extends RestrictedProcess {
|
||||
|
||||
private RedisUtil redis;
|
||||
private SmsRedisUtil redis;
|
||||
private static final Long minTimer = 60 * 1000L;
|
||||
private static final Long accTimer = 24 * 60 * 60 * 1000L;
|
||||
private static final String REDIS_KEY = "sms:restricted:";
|
||||
|
||||
public SolonRestrictedProcess(AopContext context){
|
||||
context.getBeanAsync(RedisUtil.class, bean->{
|
||||
context.getBeanAsync(SmsRedisUtil.class, bean->{
|
||||
redis = bean;
|
||||
});
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ package org.dromara.sms4j.solon.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.smsProxy.SmsInvocationHandler;
|
||||
import org.dromara.sms4j.api.universal.RedisUtil;
|
||||
import org.dromara.sms4j.api.universal.SmsRedisUtil;
|
||||
import org.dromara.sms4j.comm.config.SmsBanner;
|
||||
import org.dromara.sms4j.comm.config.SmsConfig;
|
||||
import org.dromara.sms4j.comm.config.SmsSqlConfig;
|
||||
@ -11,7 +11,7 @@ import org.dromara.sms4j.comm.delayedTime.DelayedTime;
|
||||
import org.dromara.sms4j.comm.factory.BeanFactory;
|
||||
import org.dromara.sms4j.core.SupplierSqlConfig;
|
||||
import org.dromara.sms4j.solon.aop.SolonRestrictedProcess;
|
||||
import org.dromara.sms4j.solon.utils.RedisUtils;
|
||||
import org.dromara.sms4j.solon.utils.SmsRedisUtils;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.Utils;
|
||||
import org.noear.solon.annotation.*;
|
||||
@ -82,8 +82,8 @@ public class SmsAutowiredConfig implements LifecycleBean {
|
||||
/* 如果配置中启用了redis,则注入redis工具*/
|
||||
if (BeanFactory.getSmsConfig().getRedisCache()) {
|
||||
//如果容器中不存在一个已经实现的redisUtil则自己注入一个
|
||||
if (!Solon.context().hasWrap(RedisUtil.class)) {
|
||||
Solon.context().wrapAndPut(RedisUtils.class);
|
||||
if (!Solon.context().hasWrap(SmsRedisUtil.class)) {
|
||||
Solon.context().wrapAndPut(SmsRedisUtils.class);
|
||||
}
|
||||
SmsInvocationHandler.setRestrictedProcess(new SolonRestrictedProcess(aopContext));
|
||||
log.debug("The redis cache is enabled for sms4j");
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package org.dromara.sms4j.solon.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.universal.RedisUtil;
|
||||
import org.dromara.sms4j.api.universal.SmsRedisUtil;
|
||||
import org.noear.solon.Solon;
|
||||
import org.redisson.api.RedissonClient;
|
||||
|
||||
@ -10,11 +10,11 @@ import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
public class RedisUtils implements RedisUtil {
|
||||
public class SmsRedisUtils implements SmsRedisUtil {
|
||||
|
||||
private RedissonClient redisTemplate;
|
||||
|
||||
public RedisUtils() {
|
||||
public SmsRedisUtils() {
|
||||
Thread t = new Thread(()->{
|
||||
//如果获取到的bean为null则等待后重试,最多重试五次
|
||||
for(int i = 0; i < 5 ;i++){
|
||||
@ -34,7 +34,7 @@ public class RedisUtils implements RedisUtil {
|
||||
t.start();
|
||||
}
|
||||
|
||||
public RedisUtils(RedissonClient redisTemplate) {
|
||||
public SmsRedisUtils(RedissonClient redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
@ -2,11 +2,11 @@ package org.dromara.sms4j.starter.aop;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.smsProxy.RestrictedProcess;
|
||||
import org.dromara.sms4j.api.universal.SmsRedisUtil;
|
||||
import org.dromara.sms4j.comm.config.SmsConfig;
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
import org.dromara.sms4j.comm.utils.SmsUtil;
|
||||
import org.dromara.sms4j.api.universal.RedisUtil;
|
||||
import org.dromara.sms4j.starter.utils.SpringUtil;
|
||||
import org.dromara.sms4j.starter.utils.SmsSpringUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ -19,7 +19,7 @@ public class RestrictedProcessImpl extends RestrictedProcess {
|
||||
|
||||
@Override
|
||||
public SmsBlendException process(SmsConfig config,String args) throws Exception {
|
||||
RedisUtil redis = SpringUtil.getBean(RedisUtil.class);
|
||||
SmsRedisUtil redis = SmsSpringUtil.getBean(SmsRedisUtil.class);
|
||||
if (Objects.isNull(redis)){
|
||||
throw new SmsBlendException("The redis tool could not be found");
|
||||
}
|
||||
|
||||
@ -2,19 +2,18 @@ package org.dromara.sms4j.starter.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.smsProxy.SmsInvocationHandler;
|
||||
import org.dromara.sms4j.api.universal.SmsRedisUtil;
|
||||
import org.dromara.sms4j.comm.config.SmsBanner;
|
||||
import org.dromara.sms4j.comm.config.SmsConfig;
|
||||
import org.dromara.sms4j.comm.config.SmsSqlConfig;
|
||||
import org.dromara.sms4j.comm.constant.Constant;
|
||||
import org.dromara.sms4j.comm.delayedTime.DelayedTime;
|
||||
import org.dromara.sms4j.comm.factory.BeanFactory;
|
||||
import org.dromara.sms4j.comm.utils.JDBCTool;
|
||||
import org.dromara.sms4j.core.SupplierSqlConfig;
|
||||
import org.dromara.sms4j.starter.aop.RestrictedProcessImpl;
|
||||
import org.dromara.sms4j.api.universal.RedisUtil;
|
||||
import org.dromara.sms4j.starter.utils.ConfigUtil;
|
||||
import org.dromara.sms4j.starter.utils.RedisUtils;
|
||||
import org.dromara.sms4j.starter.utils.SpringUtil;
|
||||
import org.dromara.sms4j.starter.utils.SmsRedisUtils;
|
||||
import org.dromara.sms4j.starter.utils.SmsSpringUtil;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -30,10 +29,10 @@ import java.util.concurrent.Executor;
|
||||
@Slf4j
|
||||
public class SmsAutowiredConfig {
|
||||
|
||||
private final SpringUtil springUtil;
|
||||
private final SmsSpringUtil smsSpringUtil;
|
||||
|
||||
public SmsAutowiredConfig(SpringUtil springUtil) {
|
||||
this.springUtil = springUtil;
|
||||
public SmsAutowiredConfig(SmsSpringUtil smsSpringUtil) {
|
||||
this.smsSpringUtil = smsSpringUtil;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ -75,7 +74,7 @@ public class SmsAutowiredConfig {
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "sms", name = "config-type", havingValue = "sql_config")
|
||||
protected SupplierSqlConfig supplierSqlConfig(SmsSqlConfig smsSqlConfig) throws SQLException {
|
||||
DataSource bean = SpringUtil.getBean(DataSource.class);
|
||||
DataSource bean = SmsSpringUtil.getBean(DataSource.class);
|
||||
if (!Objects.isNull(bean)){
|
||||
BeanFactory.getJDBCTool().setConnection(bean.getConnection());
|
||||
}
|
||||
@ -86,8 +85,8 @@ public class SmsAutowiredConfig {
|
||||
/* 如果配置中启用了redis,则注入redis工具*/
|
||||
if (BeanFactory.getSmsConfig().getRedisCache()){
|
||||
//如果用户没有实现RedisUtil接口则注入默认的实现
|
||||
if (!SpringUtil.interfaceExist(RedisUtil.class)){
|
||||
springUtil.createBean(RedisUtils.class);
|
||||
if (!SmsSpringUtil.interfaceExist(SmsRedisUtil.class)){
|
||||
smsSpringUtil.createBean(SmsRedisUtils.class);
|
||||
}
|
||||
SmsInvocationHandler.setRestrictedProcess(new RestrictedProcessImpl());
|
||||
log.debug("The redis cache is enabled for sms4j");
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package org.dromara.sms4j.starter.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.sms4j.starter.utils.SpringUtil;
|
||||
import org.dromara.sms4j.starter.utils.SmsSpringUtil;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -11,14 +11,14 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class SmsMainConfig {
|
||||
|
||||
@Bean
|
||||
public SpringUtil springUtil(DefaultListableBeanFactory defaultListableBeanFactory){
|
||||
return new SpringUtil(defaultListableBeanFactory);
|
||||
public SmsSpringUtil smsSpringUtil(DefaultListableBeanFactory defaultListableBeanFactory){
|
||||
return new SmsSpringUtil(defaultListableBeanFactory);
|
||||
}
|
||||
|
||||
/** 主要配置注入 确保springUtil注入后再注入*/
|
||||
@Bean(initMethod = "init")
|
||||
public SmsAutowiredConfig smsAutowiredConfig(SpringUtil springUtil){
|
||||
return new SmsAutowiredConfig(springUtil);
|
||||
public SmsAutowiredConfig smsAutowiredConfig(SmsSpringUtil smsSpringUtil){
|
||||
return new SmsAutowiredConfig(smsSpringUtil);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package org.dromara.sms4j.starter.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.universal.RedisUtil;
|
||||
import org.dromara.sms4j.api.universal.SmsRedisUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class RedisUtils implements RedisUtil {
|
||||
public class SmsRedisUtils implements SmsRedisUtil {
|
||||
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@ -41,10 +41,10 @@ public class RedisUtils implements RedisUtil {
|
||||
this.redisTemplate = template;
|
||||
}
|
||||
|
||||
public RedisUtils() {
|
||||
public SmsRedisUtils() {
|
||||
}
|
||||
|
||||
public RedisUtils(RedisTemplate<String, Object> redisTemplate) {
|
||||
public SmsRedisUtils(RedisTemplate<String, Object> redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
@ -8,20 +8,20 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
/**
|
||||
* <p>类名: SpringUtil
|
||||
* <p>类名: SmsSpringUtil
|
||||
* <p>说明:spring bean工具
|
||||
*
|
||||
* @author :Wind
|
||||
* 2023/3/25 0:13
|
||||
**/
|
||||
@Slf4j
|
||||
public class SpringUtil implements ApplicationContextAware {
|
||||
public class SmsSpringUtil implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
private final DefaultListableBeanFactory beanFactory;
|
||||
|
||||
public SpringUtil(DefaultListableBeanFactory beanFactory) {
|
||||
public SmsSpringUtil(DefaultListableBeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
@ -31,8 +31,8 @@ public class SpringUtil implements ApplicationContextAware {
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
if (SpringUtil.applicationContext == null) {
|
||||
SpringUtil.applicationContext = applicationContext;
|
||||
if (SmsSpringUtil.applicationContext == null) {
|
||||
SmsSpringUtil.applicationContext = applicationContext;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user