Class SpringContextFailoverScanner

java.lang.Object
com.societegenerale.failover.scanner.SpringContextFailoverScanner
All Implemented Interfaces:
FailoverScanner, org.springframework.beans.factory.Aware, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.context.ApplicationContextAware

public class SpringContextFailoverScanner extends Object implements FailoverScanner, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.SmartInitializingSingleton
FailoverScanner backed by the Spring ApplicationContext.

Implements SmartInitializingSingleton so it runs after all singleton beans have been instantiated — the correct lifecycle point to see every registered bean. It enumerates bean definitions, unwraps CGLIB proxies via ClassUtils.getUserClass(java.lang.Object), then walks each class's method hierarchy with ReflectionUtils.doWithMethods(java.lang.Class<?>, org.springframework.util.ReflectionUtils.MethodCallback) using Spring's AnnotationUtils.findAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class<A>) so that @Failover placed on an interface method is found even when the concrete class does not repeat it.

Works with Spring-managed beans only — methods on plain Java objects not registered in the Spring context are not visible to this scanner.

Author:
Anand Manissery
  • Constructor Details

    • SpringContextFailoverScanner

      public SpringContextFailoverScanner()
  • Method Details

    • setApplicationContext

      public void setApplicationContext(@Nullable org.springframework.context.ApplicationContext applicationContext)
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
    • afterSingletonsInstantiated

      public void afterSingletonsInstantiated()
      Scans all registered singleton beans for methods annotated with Failover. Called by Spring after every singleton bean has been instantiated.
      Specified by:
      afterSingletonsInstantiated in interface org.springframework.beans.factory.SmartInitializingSingleton
    • findFailoverByName

      public @Nullable Failover findFailoverByName(String name)
      Description copied from interface: FailoverScanner
      Returns the Failover annotation with the given name, or null if not found.
      Specified by:
      findFailoverByName in interface FailoverScanner
      Parameters:
      name - the value of Failover.name()
      Returns:
      the matching annotation, or null
    • findAllFailover

      public List<Failover> findAllFailover()
      Description copied from interface: FailoverScanner
      Returns all Failover annotations discovered during scanning.
      Specified by:
      findAllFailover in interface FailoverScanner
      Returns:
      list of all failover annotations; never null
    • findAllPayloadTypes

      public Set<Class<?>> findAllPayloadTypes()
      Description copied from interface: FailoverScanner
      Returns the payload types discovered on @Failover methods: each method's return type, or — for a method returning a Collection or array — its element/component type.

      Used to build a secure-by-default deserialization allowlist for serializing stores (the packages of these types are trusted). Returns an empty set by default for implementations that do not track types.

      Specified by:
      findAllPayloadTypes in interface FailoverScanner
      Returns:
      discovered payload types; never null