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.datacenter-id and snowflake.worker-id; no @Import or other manual wiring is required.

  • Constructor Details

    • SnowflakeAutoConfiguration

      public SnowflakeAutoConfiguration()
  • Method Details

    • snowflakeConfig

      @Bean public SnowflakeConfig snowflakeConfig(SnowflakeProperties properties)
      Parameters:
      properties - the bound snowflake.* configuration, providing datacenterId, workerId and epoch
      Returns:
      the layout and identity configuration for this application instance
    • idGenerator

      @Bean public IdGenerator idGenerator(SnowflakeConfig config, 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:
      config - the shared SnowflakeConfig for this instance
      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
    • snowflakeHealthIndicator

      @Bean @ConditionalOnClass(org.springframework.boot.health.contributor.HealthIndicator.class) public org.springframework.boot.health.contributor.HealthIndicator snowflakeHealthIndicator(SnowflakeConfig config)
      Exposes datacenterId, workerId and the timestamp overflow horizon through /actuator/health, so operators can check this instance's Snowflake identity and epoch headroom without reading logs. Only registered when Spring Boot Actuator is on the classpath.
      Parameters:
      config - the shared SnowflakeConfig for this instance
      Returns:
      a health indicator reporting static identity and epoch details