Class SnowflakeAutoConfiguration
java.lang.Object
com.fayupable.snowflake.jpaspring.SnowflakeAutoConfiguration
@Configuration
@EnableConfigurationProperties(SnowflakeProperties.class)
public class SnowflakeAutoConfiguration
extends Object
Wires a Spring-managed
IdGenerator from SnowflakeProperties and
publishes it to SnowflakeIdGeneratorHolder, since Hibernate instantiates
SnowflakeIdentifierGenerator via reflection and never asks the
ApplicationContext for it. This class is the one place that bridges the two.
Registered automatically through
META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports,
the same mechanism every official Spring Boot starter uses. Consumers only need to
add the snowflake-jpa-spring dependency and set snowflake.node-id;
no @Import or other manual wiring is required.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionidGenerator(SnowflakeProperties properties, org.springframework.beans.factory.ObjectProvider<io.micrometer.core.instrument.MeterRegistry> registryProvider) Creates the singletonIdGeneratorfor this application instance and registers it withSnowflakeIdGeneratorHolderso that@SnowflakeGeneratedId-annotated entity fields can be populated by Hibernate.
-
Constructor Details
-
SnowflakeAutoConfiguration
public SnowflakeAutoConfiguration()
-
-
Method Details
-
idGenerator
@Bean public IdGenerator idGenerator(SnowflakeProperties properties, org.springframework.beans.factory.ObjectProvider<io.micrometer.core.instrument.MeterRegistry> registryProvider) Creates the singletonIdGeneratorfor this application instance and registers it withSnowflakeIdGeneratorHolderso that@SnowflakeGeneratedId-annotated entity fields can be populated by Hibernate.- Parameters:
properties- the boundsnowflake.*configuration, providingnodeIdandepochregistryProvider- the application'sMeterRegistry, if one exists; when absent, generator activity is simply not measured, no metrics backend is required- Returns:
- a thread-safe
IdGeneratorbacked by the real system clock, exposed as a regular Spring bean in case other components want to generate ids directly (e.g. for non-JPA use cases) via normal dependency injection instead of the static holder
-