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

      public abstract class AbstractBeanSelectionProvider
      extends Object
      implements BeanSelectionProvider

  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:

  1. Read the property value for the given key from the configuration properties
  2. If no property is set, use "struts" as the default bean name
  3. Check if a bean with that name already exists in the container:
     - If found, alias it to `Container.DEFAULT_NAME` making it the default
     - If not found, try to load the property value as a fully qualified class name
  4. If class loading succeeds, register the class as a factory for the interface type
  5. If class loading fails and the name is not the default, create a delegate factory that will resolve the bean through `ObjectFactory` at 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);

  See Also:
    `BeanSelectionProvider`, `StrutsBeanSelectionProvider`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DEFAULT_BEAN_NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractBeanSelectionProvider()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `alias(Class type, String key, ContainerBuilder builder, Properties props)`
    `protected void` | `alias(Class type, String key, ContainerBuilder builder, Properties props, Scope scope)`
    `void` | `destroy()` Called before removed from the configuration manager
    `void` | `init(Configuration configuration)` Initializes with the configuration
    `void` | `loadPackages()` Loads the packages for the configuration.
    `boolean` | `needsReload()` Tells whether the ContainerProvider should reload its configuration

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.opensymphony.xwork2.config.ContainerProvider

      `register`

- - ### Field Detail

    - #### DEFAULT_BEAN_NAME

          public static final String DEFAULT_BEAN_NAME

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### AbstractBeanSelectionProvider

          public AbstractBeanSelectionProvider()

  - ### Method Detail

    - #### destroy

          public void destroy()

      Description copied from interface: `ContainerProvider`
      Called before removed from the configuration manager
      Specified by:
        `destroy` in interface `ContainerProvider`

    - #### loadPackages

          public void loadPackages()
                            throws ConfigurationException

      Description copied from interface: `PackageProvider`
      Loads the packages for the configuration.
      Specified by:
        `loadPackages` in interface `PackageProvider`
      Throws:
        `ConfigurationException` - in case of configuration errors

    - #### init

          public void init(Configuration configuration)
                    throws ConfigurationException

      Description copied from interface: `ContainerProvider`
      Initializes with the configuration
      Specified by:
        `init` in interface `ContainerProvider`
      Specified by:
        `init` in interface `PackageProvider`
      Parameters:
        `configuration` - The configuration
      Throws:
        `ConfigurationException` - If anything goes wrong

    - #### needsReload

          public boolean needsReload()

      Description copied from interface: `ContainerProvider`
      Tells whether the ContainerProvider should reload its configuration
      Specified by:
        `needsReload` in interface `ContainerProvider`
      Specified by:
        `needsReload` in interface `PackageProvider`
      Returns:
        `true`, whether the ContainerProvider should reload its configuration, `false`otherwise.

    - #### alias

          protected void alias(Class type,
                               String key,
                               ContainerBuilder builder,
                               Properties props)

    - #### alias

          protected void alias(Class type,
                               String key,
                               ContainerBuilder builder,
                               Properties props,
                               Scope scope)

Copyright © 2000–2026 Apache Software Foundation. All rights reserved.