Class LoggedAutoConfiguration

java.lang.Object
com.fayupable.logged.spring.config.LoggedAutoConfiguration

@AutoConfiguration @EnableConfigurationProperties(LoggedProperties.class) public class LoggedAutoConfiguration extends Object
Auto-configuration that wires the default port implementations and LoggedAspect into a Spring Boot application, so that adding this module as a dependency is enough for @Logged to work without any further setup.

Every bean declared here is guarded by ConditionalOnMissingBean, so an application can override any single collaborator (for example to provide a custom InvocationEventEmitter that forwards events to a message queue) simply by declaring its own bean of that type; this auto-configuration then backs off for that collaborator only, leaving the others in place.

MetricsRecorder resolves, through LazyMetricsRecorder, to a MicrometerMetricsRecorder if a MeterRegistry bean turns out to exist once the application has actually started, and to a no-op recorder otherwise. This choice is deliberately deferred to the first real invocation rather than decided during context refresh: whether a MeterRegistry bean exists at a given point during auto-configuration processing depends on an ordering between this module and Actuator's own auto-configuration that cannot be reliably pinned across Spring Boot versions, whereas resolving lazily is unaffected by that ordering entirely.

IClientInfoPort resolves in three tiers: SpringSecurityClientInfoAdapter when Spring Security and Spring Web are both present (authentication-aware, with an IP fallback); HttpRequestClientInfoAdapter when only Spring Web is present (IP resolution has nothing to do with Spring Security, so a service without it still gets real caller IPs instead of always reporting "unknown"); and NoOpClientInfoPort when neither is present.

  • Constructor Details

    • LoggedAutoConfiguration

      public LoggedAutoConfiguration()
  • Method Details

    • loggedTargetGuardBeanPostProcessor

      @Bean public static LoggedTargetGuardBeanPostProcessor loggedTargetGuardBeanPostProcessor()
      Registered as a static bean method, per Spring's own guidance for BeanPostProcessor beans: this ensures the processor is created early enough to inspect every other bean in this context, without triggering premature instantiation of this configuration class itself.
      Returns:
      the guard that rejects @Logged on disallowed targets
    • invocationEventEmitter

      @Bean @ConditionalOnMissingBean(InvocationEventEmitter.class) public InvocationEventEmitter invocationEventEmitter()
    • springSecurityClientInfoAdapter

      @Bean @ConditionalOnMissingBean(IClientInfoPort.class) @ConditionalOnClass({org.springframework.security.core.Authentication.class,jakarta.servlet.http.HttpServletRequest.class}) public IClientInfoPort springSecurityClientInfoAdapter(LoggedProperties properties)
    • httpRequestClientInfoAdapter

      @Bean @ConditionalOnMissingBean(IClientInfoPort.class) @ConditionalOnClass(jakarta.servlet.http.HttpServletRequest.class) public IClientInfoPort httpRequestClientInfoAdapter(LoggedProperties properties)
    • noOpClientInfoPort

      @Bean @ConditionalOnMissingBean(IClientInfoPort.class) public IClientInfoPort noOpClientInfoPort()
    • metricsRecorder

      @Bean @ConditionalOnMissingBean(MetricsRecorder.class) @ConditionalOnClass(io.micrometer.core.instrument.MeterRegistry.class) @ConditionalOnProperty(prefix="logged.metrics", name="enabled", havingValue="true", matchIfMissing=true) public MetricsRecorder metricsRecorder(org.springframework.beans.factory.ObjectProvider<io.micrometer.core.instrument.MeterRegistry> meterRegistryProvider)
    • noOpMetricsRecorder

      @Bean @ConditionalOnMissingBean(MetricsRecorder.class) public MetricsRecorder noOpMetricsRecorder()
    • loggedAspect

      @Bean @ConditionalOnMissingBean(LoggedAspect.class) @ConditionalOnProperty(prefix="logged", name="enabled", havingValue="true", matchIfMissing=true) public LoggedAspect loggedAspect(InvocationEventEmitter eventEmitter, MetricsRecorder metricsRecorder, IClientInfoPort clientInfoPort)