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 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 singleton IdGenerator for this application instance and registers it with SnowflakeIdGeneratorHolder so that @SnowflakeGeneratedId-annotated entity fields can be populated by Hibernate.
      Parameters:
      properties - the bound snowflake.* configuration, providing nodeId and epoch
      registryProvider - the application's MeterRegistry, if one exists; when absent, generator activity is simply not measured, no metrics backend is required
      Returns:
      a thread-safe IdGenerator backed 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