Package org.apache.struts2.config
Class AbstractBeanSelectionProvider
java.lang.Object
org.apache.struts2.config.AbstractBeanSelectionProvider
- All Implemented Interfaces:
BeanSelectionProvider,ConfigurationProvider,ContainerProvider,PackageProvider
- Direct Known Subclasses:
StrutsBeanSelectionProvider
Base implementation of
BeanSelectionProvider that provides bean aliasing functionality.
This class provides the alias(Class, String, ContainerBuilder, Properties, Scope) method
which is used to select and register bean implementations based on configuration properties.
Bean Selection Process
The alias method selects a bean implementation using the following process:
- Read the property value for the given key from the configuration properties
- If no property is set, use "struts" as the default bean name
- Check if a bean with that name already exists in the container:
- If found, alias it to
Container.DEFAULT_NAMEmaking it the default - If not found, try to load the property value as a fully qualified class name
- If found, alias it to
- If class loading succeeds, register the class as a factory for the interface type
- If class loading fails and the name is not the default, create a delegate factory
that will resolve the bean through
ObjectFactoryat runtime. This allows Spring bean names to be used in configuration.
Usage Example
// In struts.properties or struts.xml: // struts.objectFactory = spring // struts.converter.collection = myCustomCollectionConverter // In a subclass: alias(ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY, builder, props); alias(CollectionConverter.class, StrutsConstants.STRUTS_CONVERTER_COLLECTION, builder, props);
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidalias(Class type, String key, ContainerBuilder builder, Properties props) protected voidalias(Class type, String key, ContainerBuilder builder, Properties props, Scope scope) voiddestroy()Called before removed from the configuration managervoidinit(Configuration configuration) Initializes with the configurationvoidLoads the packages for the configuration.booleanTells whether the ContainerProvider should reload its configurationMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.struts2.config.ContainerProvider
register
-
Field Details
-
DEFAULT_BEAN_NAME
- See Also:
-
-
Constructor Details
-
AbstractBeanSelectionProvider
public AbstractBeanSelectionProvider()
-
-
Method Details
-
destroy
public void destroy()Description copied from interface:ContainerProviderCalled before removed from the configuration manager- Specified by:
destroyin interfaceContainerProvider
-
loadPackages
Description copied from interface:PackageProviderLoads the packages for the configuration.- Specified by:
loadPackagesin interfacePackageProvider- Throws:
ConfigurationException- in case of configuration errors
-
init
Description copied from interface:ContainerProviderInitializes with the configuration- Specified by:
initin interfaceContainerProvider- Specified by:
initin interfacePackageProvider- Parameters:
configuration- The configuration- Throws:
ConfigurationException- If anything goes wrong
-
needsReload
public boolean needsReload()Description copied from interface:ContainerProviderTells whether the ContainerProvider should reload its configuration- Specified by:
needsReloadin interfaceContainerProvider- Specified by:
needsReloadin interfacePackageProvider- Returns:
- true, whether the ContainerProvider should reload its configuration, falseotherwise.
-
alias
-
alias
protected void alias(Class type, String key, ContainerBuilder builder, Properties props, Scope scope)
-