All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dengchen2020.id.config.SnowflakeAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 0.0.35
Show newest version
package io.github.dengchen2020.id.config;

import io.github.dengchen2020.id.properties.IdGeneratorBuilder;
import io.github.dengchen2020.id.snowflake.SnowflakeSmartLifecycle;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * 雪花算法自动配置
 * 

依赖redis,需引入

*
{@code
 * 
 *     org.springframework.boot
 *     spring-boot-starter-data-redis
 *     latest
 * }
* @author 邓郴 * @since 2024/7/2 */ @ConditionalOnClass(RedisConnectionFactory.class) @EnableConfigurationProperties(IdGeneratorBuilder.class) @ConditionalOnProperty(value = "dc.id.type",matchIfMissing = true,havingValue = "snowflake") @AutoConfigureAfter(RedisReactiveAutoConfiguration.class) @Configuration(proxyBeanMethods = false) public class SnowflakeAutoConfiguration { @ConditionalOnSingleCandidate(RedisConnectionFactory.class) @Bean public SnowflakeSmartLifecycle snowflakeSmartLifecycle(RedisConnectionFactory redisConnectionFactory, IdGeneratorBuilder idGeneratorBuilder){ return new SnowflakeSmartLifecycle(new StringRedisTemplate(redisConnectionFactory),idGeneratorBuilder.getSnowflake()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy