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 TypeMethodDescription<T> Set<T> findByType(Class<T> type) Finds beans in the registry by their type.findByTypeWithName(Class<T> type) Finds beans in the registry by their type.default <T> @Nullable TfindSingleByType(Class<T> type) Finds the bean by type, if there is exactly only one instance of the bean@Nullable ObjectlookupByName(String name) Looks up a bean in the registry based purely on name, returning the bean or null if it could not be found.<T> @Nullable TlookupByNameAndType(String name, Class<T> type) Looks up a bean in the registry, returning the bean or null if it could not be found.default <T> TmandatoryFindSingleByType(Class<T> type) Finds the bean by type, if there is exactly only one instance of the beandefault ObjectStrategy to wrap the value to be stored in the registry.
-
Method Details
-
lookupByName
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 thelookupByNameAndType(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
-
findByTypeWithName
-
findByType
-
findSingleByType
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
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
NoSuchBeanTypeExceptionif not exactly one bean was found.
-
unwrap
-