Class ConfigurationPropertiesRebinder

java.lang.Object
org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder
All Implemented Interfaces:
EventListener, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<EnvironmentChangeEvent>

@Component @ManagedResource public class ConfigurationPropertiesRebinder extends Object implements org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<EnvironmentChangeEvent>
Listens for EnvironmentChangeEvent and rebinds beans that were bound to the Environment using @ConfigurationProperties. When these beans are re-bound and re-initialized, the changes are available immediately to any component that is using the @ConfigurationProperties bean.

Rebinding a given bean is serialized against other concurrent rebinds of that same bean, so two overlapping refreshes (for example a manual rebind(String) call racing with an EnvironmentChangeEvent-triggered rebind()) cannot interleave their destroy/reset/re-initialize steps. That does not, however, make the bean safe to read concurrently from other threads while a rebind is in progress: the bean is mutated in place, field by field, so a concurrent reader can observe transient intermediate state. Beans that need a consistent view across a refresh should use RefreshScope instead, which serializes reads against refreshes via a per-bean ReadWriteLock.

Author:
Dave Syer, Yanming Zhou
See Also:
  • Constructor Details

  • Method Details

    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • getErrors

      public Map<String,Exception> getErrors()
      A map of bean name to errors when instantiating the bean.
      Returns:
      The errors accumulated since the latest destroy.
    • rebind

      @ManagedOperation public void rebind()
    • rebind

      @ManagedOperation public boolean rebind(String name)
    • rebind

      public boolean rebind(Class type)
      WARNING: This method rebinds beans from any context in the hierarchy using the main application context.
      Parameters:
      type - bean type to rebind.
      Returns:
      true, if successful.
    • getNeverRefreshable

      @ManagedAttribute public Set<String> getNeverRefreshable()
    • getBeanNames

      @ManagedAttribute public Set<String> getBeanNames()
    • onApplicationEvent

      public void onApplicationEvent(EnvironmentChangeEvent event)
      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<EnvironmentChangeEvent>