mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-11 13:19:01 +08:00
🐛 Fixing a bug. #614 发号器sequence使用默认配置会报错
This commit is contained in:
1 parent
45bf557b6f
commit
348b72eb74
2 files changed
+2
-53
No files matched your search
-51
@@ -17,24 +17,15 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.sequence;
|
||||
|
||||
import com.pig4cloud.pigx.common.sequence.builder.DbSeqBuilder;
|
||||
import com.pig4cloud.pigx.common.sequence.builder.RedisSeqBuilder;
|
||||
import com.pig4cloud.pigx.common.sequence.builder.SnowflakeSeqBuilder;
|
||||
import com.pig4cloud.pigx.common.sequence.properties.SequenceDbProperties;
|
||||
import com.pig4cloud.pigx.common.sequence.properties.SequenceRedisProperties;
|
||||
import com.pig4cloud.pigx.common.sequence.properties.SequenceSnowflakeProperties;
|
||||
import com.pig4cloud.pigx.common.sequence.range.impl.name.DateBizName;
|
||||
import com.pig4cloud.pigx.common.sequence.range.impl.name.DefaultBizName;
|
||||
import com.pig4cloud.pigx.common.sequence.sequence.Sequence;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019-05-26
|
||||
@@ -44,48 +35,6 @@ import javax.sql.DataSource;
|
||||
@ConditionalOnMissingBean(Sequence.class)
|
||||
public class SequenceAutoConfiguration {
|
||||
|
||||
/**
|
||||
* 数据库作为发号器的存储介质
|
||||
*
|
||||
* @param dataSource
|
||||
* @param properties
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnBean(SequenceDbProperties.class)
|
||||
public Sequence dbSequence(DataSource dataSource,
|
||||
SequenceDbProperties properties) {
|
||||
return DbSeqBuilder
|
||||
.create()
|
||||
.bizName(new DefaultBizName(properties.getBizName()))
|
||||
.dataSource(dataSource)
|
||||
.step(properties.getStep())
|
||||
.retryTimes(properties.getRetryTimes())
|
||||
.tableName(properties.getTableName())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redis 作为发号器的存储介质
|
||||
*
|
||||
* @param redisProperties
|
||||
* @param properties
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnBean(SequenceRedisProperties.class)
|
||||
public Sequence redisSequence(RedisProperties redisProperties,
|
||||
SequenceRedisProperties properties) {
|
||||
return RedisSeqBuilder
|
||||
.create()
|
||||
.bizName(new DateBizName(properties.getBizName()))
|
||||
.ip(redisProperties.getHost())
|
||||
.port(redisProperties.getPort())
|
||||
.auth(redisProperties.getPassword())
|
||||
.step(properties.getStep())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* snowflak 算法作为发号器实现
|
||||
*
|
||||
|
||||
+2
-2
@@ -22,10 +22,10 @@ public class SequenceDbProperties extends BaseSequenceProperties {
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String tableName;
|
||||
private String tableName = "pigx_sequence";
|
||||
/**
|
||||
* 重试次数
|
||||
*/
|
||||
private int retryTimes;
|
||||
private int retryTimes = 1;
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user