Interface BeanRepository

All Known Subinterfaces:
Registry

public interface BeanRepository
Pluggable contract for looking up beans by name or type, forming the foundation of Camel's Registry.

At runtime, the active CamelContext exposes a composite Registry that delegates to one or more BeanRepository instances, allowing Camel to integrate with external containers such as Spring ApplicationContext, CDI, JNDI, or OSGi service registries without changes to core code. The composited view is used transparently whenever a route references a bean by name (for example in the .bean() DSL call) or when Camel auto-wires component options from the registry.

Lookup is available in three forms: by name only (lookupByName(String)), by name and expected type (lookupByNameAndType(String, Class)), and by type alone (findByType(Class) / findByTypeWithName(Class)). Prefer the typed variants to avoid ambiguity when the same name is bound more than once.

Since:
3.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> Set<T>
    findByType(Class<T> type)
    Finds beans in the registry by their type.
    <T> Map<String,T>
    Finds beans in the registry by their type.
    default <T> @Nullable T
    Finds the bean by type, if there is exactly only one instance of the bean
    @Nullable Object
    Looks up a bean in the registry based purely on name, returning the bean or null if it could not be found.
    <T> @Nullable T
    Looks up a bean in the registry, returning the bean or null if it could not be found.
    default <T> T
    Finds the bean by type, if there is exactly only one instance of the bean
    default Object
    unwrap(Object value)
    Strategy to wrap the value to be stored in the registry.
  • Method Details

    • lookupByName

      @Nullable Object lookupByName(String name)
      Looks up a bean in the registry based purely on name, returning the bean or null if it could not be found.

      Important: Multiple beans of different types may be bound with the same name, and its encouraged to use the lookupByNameAndType(String, Class) to lookup the bean with a specific type, or to use any of the find methods.

      Parameters:
      name - the name of the bean
      Returns:
      the bean from the registry or null if it could not be found
    • lookupByNameAndType

      <T> @Nullable T lookupByNameAndType(String name, Class<T> type)
      Looks up a bean in the registry, returning the bean or null if it could not be found.
      Parameters:
      name - the name of the bean
      type - the type of the required bean
      Returns:
      the bean from the registry or null if it could not be found
    • findByTypeWithName

      <T> Map<String,T> findByTypeWithName(Class<T> type)
      Finds beans in the registry by their type.
      Parameters:
      type - the type of the beans
      Returns:
      the types found, with their bean ids as the key. Returns an empty Map if none found.
    • findByType

      <T> Set<T> findByType(Class<T> type)
      Finds beans in the registry by their type.
      Parameters:
      type - the type of the beans
      Returns:
      the types found. Returns an empty Set if none found.
    • findSingleByType

      default <T> @Nullable T findSingleByType(Class<T> type)
      Finds the bean by type, if there is exactly only one instance of the bean
      Parameters:
      type - the type of the beans
      Returns:
      the single bean instance, or null if none found or there are more than one bean of the given type.
    • mandatoryFindSingleByType

      default <T> T mandatoryFindSingleByType(Class<T> type)
      Finds the bean by type, if there is exactly only one instance of the bean
      Parameters:
      type - the type of the beans
      Returns:
      the single bean instance, or throws NoSuchBeanTypeException if not exactly one bean was found.
    • unwrap

      default Object unwrap(Object value)
      Strategy to wrap the value to be stored in the registry.
      Parameters:
      value - the value
      Returns:
      the value to return