Package io.microsphere.spring.config
Class ConfigurationPropertyRepository
java.lang.Object
io.microsphere.spring.config.ConfigurationPropertyRepository
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.EnvironmentAware
public class ConfigurationPropertyRepository
extends Object
implements org.springframework.context.EnvironmentAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
A repository for managing
ConfigurationProperty
instances with support for configuration via Spring's Environment
.
This class provides methods to add, remove, retrieve, and manage configuration properties. It also allows integration with Spring's
lifecycle management through the InitializingBean
and DisposableBean
interfaces, as well as environment-based
property configuration through the EnvironmentAware
interface.
Configuration Properties
- "microsphere.spring.config-property-repository.max-size": Sets the maximum number of properties that can be stored in the repository. Defaults to "99999" if not specified.
Example Usage
// Create a new repository instance
ConfigurationPropertyRepository repository = new ConfigurationPropertyRepository();
// Set the environment to load max size from configuration
ConfigurableEnvironment environment = new StandardEnvironment();
repository.setEnvironment(environment);
// Initialize the repository (usually done automatically by Spring)
repository.afterPropertiesSet();
// Add a configuration property
ConfigurationProperty property = new ConfigurationProperty("my.property.name");
property.setValue("exampleValue");
repository.add(property);
// Retrieve the property
ConfigurationProperty retrieved = repository.get("my.property.name");
System.out.println(retrieved.getValue()); // Output: exampleValue
// Clean up resources when done
repository.destroy();
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
-
ConfigurationProperty
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final int
The default max size ofConfigurationPropertyRepository
static final String
The max size ofConfigurationPropertyRepository
static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(io.microsphere.beans.ConfigurationProperty configurationProperty) Add aConfigurationProperty
instancevoid
boolean
Determine whether the repository contains the specified nameio.microsphere.beans.ConfigurationProperty
createIfAbsent
(String name) Create aConfigurationProperty
instance if absentvoid
destroy()
clear the repositoryio.microsphere.beans.ConfigurationProperty
Get aConfigurationProperty
instance by nameCollection<io.microsphere.beans.ConfigurationProperty>
getAll()
Get allConfigurationProperty
instancesint
Get the max size of the repositoryio.microsphere.beans.ConfigurationProperty
Remove aConfigurationProperty
instance by namevoid
setEnvironment
(org.springframework.core.env.Environment environment)
-
Field Details
-
BEAN_NAME
- See Also:
-
PROPERTY_NAME_PREFIX
- See Also:
-
DEFAULT_MAX_SIZE_PROPERTY_VALUE
public static final int DEFAULT_MAX_SIZE_PROPERTY_VALUEThe default max size ofConfigurationPropertyRepository
-
MAX_SIZE_PROPERTY_NAME
@ConfigurationProperty(type=int.class, description="The max size of the repository for ConfigurationProperty instances", defaultValue="99999") public static final String MAX_SIZE_PROPERTY_NAMEThe max size ofConfigurationPropertyRepository
- See Also:
-
-
Constructor Details
-
ConfigurationPropertyRepository
public ConfigurationPropertyRepository()
-
-
Method Details
-
add
public void add(io.microsphere.beans.ConfigurationProperty configurationProperty) Add aConfigurationProperty
instance- Parameters:
configurationProperty
- aConfigurationProperty
instance
-
remove
Remove aConfigurationProperty
instance by name- Parameters:
name
-the name of ConfigurationProperty
-
get
Get aConfigurationProperty
instance by name- Parameters:
name
-the name of ConfigurationProperty
- Returns:
null
if not found
-
contains
Determine whether the repository contains the specified name- Parameters:
name
-the name of ConfigurationProperty
- Returns:
true
if contains, otherwisefalse
-
createIfAbsent
Create aConfigurationProperty
instance if absent- Parameters:
name
-the name of ConfigurationProperty
- Returns:
- the
ConfigurationProperty
instance
-
getAll
Get allConfigurationProperty
instances- Returns:
- never
null
-
getMaxSize
public int getMaxSize()Get the max size of the repository- Returns:
- max size
-
setEnvironment
public void setEnvironment(org.springframework.core.env.Environment environment) - Specified by:
setEnvironment
in interfaceorg.springframework.context.EnvironmentAware
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
destroy
clear the repository- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
- Throws:
Exception
-
getRepository
-