Class CacheCustomizerFactoryBean

java.lang.Object
com.broadleafcommerce.common.extension.cache.CacheCustomizerFactoryBean
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.boot.cache.autoconfigure.CacheManagerCustomizer<org.springframework.cache.CacheManager>

public class CacheCustomizerFactoryBean extends Object implements org.springframework.boot.cache.autoconfigure.CacheManagerCustomizer<org.springframework.cache.CacheManager>, org.springframework.beans.factory.BeanFactoryAware
Adapts a service's static customize(...) method into a Spring Boot CacheManagerCustomizer bean. The static method registers the service's cache regions with the budget manager and returns a Consumer that registers the cache manager itself; that consumer is applied here when Spring customizes a matching cache manager.

History: this class was previously a FactoryBean that produced a dynamic proxy, in order to avoid compile-time linkage to the Spring Boot cache package (for Spring Boot 3/4 cross-compatibility). Under Spring Boot 4 that proxy was never applied: Spring Boot builds its CacheManagerCustomizers from ObjectProvider<CacheManagerCustomizer<?>> without eagerly initializing FactoryBeans, and a FactoryBean's statically-declared product type is Object, so the proxy was never recognized as a CacheManagerCustomizer and was silently excluded from the customizer list. Every service that registered its caches this way therefore never registered with the budget manager and got no cache.

Because the 3.x line targets Spring Boot 4, the cross-version reflection is no longer needed. By implementing CacheManagerCustomizer directly, the bean's type is known from its declaration (no instantiation required), so it is collected and applied like any other customizer. The class name is retained to avoid touching the many service auto-configurations that construct it.

  • Constructor Details

    • CacheCustomizerFactoryBean

      public CacheCustomizerFactoryBean(Class<?> sourceClass, String methodName, Class<?> expectedCacheManagerClass)
  • Method Details

    • setBeanFactory

      public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
    • customize

      public void customize(org.springframework.cache.CacheManager cacheManager)
      Specified by:
      customize in interface org.springframework.boot.cache.autoconfigure.CacheManagerCustomizer<org.springframework.cache.CacheManager>