-
Notifications
You must be signed in to change notification settings - Fork 39
io microsphere spring config ConfigurationPropertyRepository
Type: Class | Module: microsphere-spring-context | Package: io.microsphere.spring.config | Since: 1.0.0
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.
- `#MAX_SIZE_PROPERTY_NAME`: Sets the maximum number of properties that can be stored in the repository.
Defaults to `#DEFAULT_MAX_SIZE` if not specified.
`// 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();
`
public class ConfigurationPropertyRepository implements EnvironmentAware, InitializingBean, DisposableBeanAuthor: Mercy
-
Introduced in:
1.0.0 -
Current Project Version:
0.2.18-SNAPSHOT
This component is tested and compatible with the following Java versions:
| Java Version | Status |
|---|---|
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |
// 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();ConfigurationPropertyRepository repository = new ConfigurationPropertyRepository();
// Assume the environment has "microsphere.spring.config-property-repository.max-size=3"
repository.setEnvironment(environment);
repository.afterPropertiesSet();
assertEquals(3, repository.getMaxSize());ConfigurationPropertyRepository repository = new ConfigurationPropertyRepository();
repository.setEnvironment(environment);
repository.afterPropertiesSet();
// The repository is now ready to store ConfigurationProperty instances
repository.add(new ConfigurationProperty("my.property"));
assertTrue(repository.contains("my.property"));ConfigurationPropertyRepository repository = new ConfigurationPropertyRepository();
repository.setEnvironment(applicationContext.getEnvironment());
repository.afterPropertiesSet();
repository.add(configurationProperty);
// When shutting down
repository.destroy(); // clears all stored propertiesAdd the following dependency to your pom.xml:
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-context</artifactId>
<version>${microsphere-spring.version}</version>
</dependency>Tip: Use the BOM (
microsphere-spring-dependencies) for consistent version management. See the Getting Started guide.
import io.microsphere.spring.config.ConfigurationPropertyRepository;| Method | Description |
|---|---|
add |
The default max size of ConfigurationPropertyRepository
|
remove |
Remove a ConfigurationProperty instance by name |
get |
Get a ConfigurationProperty instance by name |
contains |
Determine whether the repository contains the specified name |
createIfAbsent |
Create a ConfigurationProperty instance if absent |
getAll |
Get all ConfigurationProperty instances |
getMaxSize |
Get the max size of the repository |
setEnvironment |
Sets the Environment and reads the maximum repository size from the |
afterPropertiesSet |
Initializes the internal repository map with a capacity derived from the configured |
destroy |
clear the repository |
public void add(ConfigurationProperty configurationProperty)The default max size of ConfigurationPropertyRepository
/
public static final int DEFAULT_MAX_SIZE_PROPERTY_VALUE = parseInt(DEFAULT_MAX_SIZE);
/**
The max size of ConfigurationPropertyRepository
/
public ConfigurationProperty remove(String name)Remove a ConfigurationProperty instance by name
public ConfigurationProperty get(String name)Get a ConfigurationProperty instance by name
public boolean contains(String name)Determine whether the repository contains the specified name
public ConfigurationProperty createIfAbsent(String name)Create a ConfigurationProperty instance if absent
public void setEnvironment(Environment environment)Sets the Environment and reads the maximum repository size from the
#MAX_SIZE_PROPERTY_NAME configuration property. Falls back to
#DEFAULT_MAX_SIZE_PROPERTY_VALUE if the property is not set.
`ConfigurationPropertyRepository repository = new ConfigurationPropertyRepository(); // Assume the environment has "microsphere.spring.config-property-repository.max-size=3" repository.setEnvironment(environment); repository.afterPropertiesSet(); assertEquals(3, repository.getMaxSize()); `
public void afterPropertiesSet()Initializes the internal repository map with a capacity derived from the configured
#getMaxSize() max size. This method is typically called automatically by
the Spring container after all properties have been set.
`ConfigurationPropertyRepository repository = new ConfigurationPropertyRepository();
repository.setEnvironment(environment);
repository.afterPropertiesSet();
// The repository is now ready to store ConfigurationProperty instances
repository.add(new ConfigurationProperty("my.property"));
assertTrue(repository.contains("my.property"));
`
public void destroy()clear the repository
`ConfigurationPropertyRepository repository = new ConfigurationPropertyRepository(); repository.setEnvironment(applicationContext.getEnvironment()); repository.afterPropertiesSet(); repository.add(configurationProperty); // When shutting down repository.destroy(); // clears all stored properties `
ConfigurationProperty
This documentation was auto-generated from the source code of microsphere-spring.
spring-context
- AbstractInjectionPointDependencyResolver
- AbstractSmartLifecycle
- AbstractSpringResourceURLConnection
- AnnotatedBeanCapableImportBeanDefinitionRegistrar
- AnnotatedBeanCapableImportCandidate
- AnnotatedBeanCapableImportSelector
- AnnotatedBeanDefinitionRegistryUtils
- AnnotatedInjectionBeanPostProcessor
- AnnotatedInjectionPointDependencyResolver
- AnnotatedPropertySourceLoader
- AnnotationBeanDefinitionRegistryPostProcessor
- AnnotationUtils
- ApplicationContextUtils
- ApplicationEventInterceptor
- ApplicationEventInterceptorChain
- ApplicationListenerInterceptor
- ApplicationListenerInterceptorChain
- AutoRegistrationBean
- AutoRegistrationBeanRegistrar
- AutowireCandidateResolvingListener
- AutowiredInjectionPointDependencyResolver
- BeanCapableImportCandidate
- BeanDefinitionUtils
- BeanDependencyResolver
- BeanFactoryListener
- BeanFactoryListenerAdapter
- BeanFactoryListeners
- BeanFactoryUtils
- BeanListener
- BeanListenerAdapter
- BeanListeners
- BeanMethodInjectionPointDependencyResolver
- BeanPropertyChangedEvent
- BeanRegistrar
- BeanSource
- BeanTimeStatistics
- BeanUtils
- CollectingConfigurationPropertyListener
- CompositeAutowireCandidateResolvingListener
- ConfigurationBeanAliasGenerator
- ConfigurationBeanBinder
- ConfigurationBeanBindingPostProcessor
- ConfigurationBeanBindingRegistrar
- ConfigurationBeanBindingsRegister
- ConfigurationBeanCustomizer
- ConfigurationPropertyOverrideAnnotationAttributesStrategy
- ConfigurationPropertyRepository
- ConstructionInjectionPointDependencyResolver
- ConversionServiceResolver
- ConversionServiceUtils
- DefaultApplicationEventInterceptorChain
- DefaultApplicationListenerInterceptorChain
- DefaultBeanDependencyResolver
- DefaultConfigurationBeanAliasGenerator
- DefaultConfigurationBeanBinder
- DefaultPropertiesPropertySource
- DefaultPropertiesPropertySourceLoader
- DefaultPropertiesPropertySources
- DefaultPropertiesPropertySourcesLoader
- DefaultResourceComparator
- DelegatingFactoryBean
- Dependency
- DependencyAnalysisBeanFactoryListener
- DependencyTreeWalker
- EnableAutoRegistrationBean
- EnableConfigurationBeanBinding
- EnableConfigurationBeanBindings
- EnableEventExtension
- EnableSpringConverterAdapter
- EnableSpringConverterAdapterRegistrar
- EnableTTLCaching
- EnvironmentListener
- EnvironmentUtils
- EventExtensionAttributes
- EventExtensionRegistrar
- EventPublishingBeanAfterProcessor
- EventPublishingBeanBeforeProcessor
- EventPublishingBeanInitializer
- ExposingClassPathBeanDefinitionScanner
- FilterMode
- GenericAnnotationAttributes
- GenericApplicationListenerAdapter
- GenericBeanNameGenerator
- GenericBeanPostProcessorAdapter
- HyphenAliasGenerator
- ImmutableMapPropertySource
- ImportOptional
- ImportOptionalSelector
- InjectionPointDependencyResolver
- InjectionPointDependencyResolvers
- InterceptingApplicationEventMulticaster
- InterceptingApplicationEventMulticasterProxy
- InterceptingApplicationListener
- JavaBeansPropertyChangeListenerAdapter
- JoinAliasGenerator
- JsonPropertySource
- JsonPropertySourceFactory
- ListenableAutowireCandidateResolver
- ListenableAutowireCandidateResolverInitializer
- ListenableConfigurableEnvironment
- ListenableConfigurableEnvironmentInitializer
- LoggingAutowireCandidateResolvingListener
- LoggingBeanFactoryListener
- LoggingBeanListener
- LoggingEnvironmentListener
- LoggingSmartLifecycle
- MethodParameterUtils
- MimeTypeUtils
- NamedBeanHolderComparator
- OnceApplicationContextEventListener
- OverrideAnnotationAttributes
- OverrideAnnotationAttributesStrategy
- ParallelPreInstantiationSingletonsBeanFactoryListener
- ProfileListener
- PropertiesUtils
- PropertyConstants
- PropertyResolverListener
- PropertyResolverUtils
- PropertySourceChangedEvent
- PropertySourceExtension
- PropertySourceExtensionAttributes
- PropertySourceExtensionLoader
- PropertySourcesChangedEvent
- PropertySourcesUtils
- PropertyValuesUtils
- ResolvableDependencyTypeFilter
- ResolvablePlaceholderAnnotationAttributes
- ResourceInjectionPointDependencyResolver
- ResourceLoaderUtils
- ResourcePropertySource
- ResourcePropertySourceLoader
- ResourcePropertySources
- ResourcePropertySourcesLoader
- ResourceUtils
- ResourceYamlProcessor
- SpringConverterAdapter
- SpringDelegatingBeanProtocolURLConnectionFactory
- SpringEnvironmentURLConnectionFactory
- SpringFactoriesLoaderUtils
- SpringProfilesURLConnectionAdapter
- SpringPropertySourcesURLConnectionAdapter
- SpringProtocolURLStreamHandler
- SpringResourceURLConnection
- SpringResourceURLConnectionAdapter
- SpringResourceURLConnectionFactory
- SpringSubProtocolURLConnectionFactory
- SpringVersion
- SpringVersionUtils
- TTLCachePut
- TTLCacheResolver
- TTLCacheable
- TTLCachingConfiguration
- TTLContext
- UnderScoreJoinAliasGenerator
- YamlPropertySource
- YamlPropertySourceFactory
spring-guice
spring-jdbc
- CompoundJdbcEventListenerFactory
- EnableP6DataSource
- NoOpP6LoadableOptions
- P6DataSourceBeanDefinitionRegistrar
- P6DataSourceBeanPostProcessor
- PropertySourcesP6LoadableOptionsAdapter
- SpringP6SpyURLConnectionFactory
spring-test
- AbstractWebFluxTest
- AbstractWebMvcTest
- AnnotatedTypeMetadataTestFactory
- EmbeddedDataBaseBeanDefinitionRegistrar
- EmbeddedDataBaseBeanDefinitionsRegistrar
- EmbeddedDatabaseType
- EmbeddedTomcatConfiguration
- EmbeddedTomcatContextLoader
- EmbeddedTomcatMergedContextConfiguration
- EmbeddedTomcatTestContextBootstrapper
- EmbeddedZookeeperServer
- EmbeddedZookeeperServerTestExecutionListener
- EnableEmbeddedDatabase
- EnableEmbeddedDatabases
- MockServletWebRequest
- PersonHandler
- PersonHandler
- RouterFunctionTestConfig
- RouterFunctionTestConfig
- ServletTestUtils
- SimpleUrlHandlerMappingTestConfig
- SimpleUrlHandlerMappingTestConfig
- SpringLoggingTest
- SpringTestUtils
- SpringTestWebUtils
- TestConditionContext
- TestController
- TestFilter
- TestFilterRegistration
- TestServlet
- TestServletContext
- TestServletContextListener
- TestServletRegistration
- User
- WebTestUtils
spring-web
- AbstractNameValueExpression
- AbstractWebEndpointMappingFactory
- AbstractWebRequestRule
- CompositeWebEndpointMappingRegistry
- CompositeWebRequestRule
- ConsumeMediaTypeExpression
- DelegatingHandlerMethodAdvice
- EnableWebExtension
- FilterRegistrationWebEndpointMappingFactory
- FilteringWebEndpointMappingRegistry
- GenericMediaTypeExpression
- HandlerMetadata
- HandlerMethodAdvice
- HandlerMethodArgumentInterceptor
- HandlerMethodArgumentsResolvedEvent
- HandlerMethodInterceptor
- HandlerMethodMetadata
- HttpUtils
- Jackson2WebEndpointMappingFactory
- MediaTypeExpression
- MediaTypeUtils
- NameValueExpression
- ProduceMediaTypeExpression
- PropertyConstants
- RegistrationWebEndpointMappingFactory
- RequestAttributesUtils
- RequestContextStrategy
- ServletRegistrationWebEndpointMappingFactory
- ServletWebEndpointMappingResolver
- SimpleWebEndpointMappingRegistry
- SmartWebEndpointMappingFactory
- SpringWebHelper
- SpringWebType
- UnknownSpringWebHelper
- WebEndpointMapping
- WebEndpointMappingFactory
- WebEndpointMappingFilter
- WebEndpointMappingRegistrar
- WebEndpointMappingRegistry
- WebEndpointMappingResolver
- WebEndpointMappingsReadyEvent
- WebEventPublisher
- WebExtensionBeanDefinitionRegistrar
- WebRequestConsumesRule
- WebRequestHeaderExpression
- WebRequestHeadersRule
- WebRequestMethodsRule
- WebRequestParamExpression
- WebRequestParamsRule
- WebRequestPattensRule
- WebRequestProducesRule
- WebRequestRule
- WebRequestUtils
- WebScope
- WebSource
- WebTarget
- WebType
- WebUtils
spring-webflux
- CompositeWebFilter
- ConsumingWebEndpointMappingAdapter
- DelegatingWebFilter
- EnableWebFluxExtension
- HandlerMappingWebEndpointMappingFactory
- HandlerMappingWebEndpointMappingResolver
- HandlerMetadataWebEndpointMappingFactory
- InterceptingHandlerMethodProcessor
- MonoUtils
- RequestContextWebFilter
- RequestHandledEventPublishingWebFilter
- RequestMappingMetadataWebEndpointMappingFactory
- RequestPredicateKind
- RequestPredicateVisitorAdapter
- ReversedProxyHandlerMapping
- RouterFunctionVisitorAdapter
- ServerRequestHandledEvent
- ServerWebRequest
- SpringWebFluxHelper
- StoringRequestBodyArgumentInterceptor
- StoringResponseBodyReturnValueInterceptor
- WebFluxExtensionBeanDefinitionRegistrar
- WebServerScope
- WebServerUtils
spring-webmvc
- AbstractPageRenderContextHandlerInterceptor
- AnnotatedMethodHandlerInterceptor
- ConfigurableContentNegotiationManagerWebMvcConfigurer
- ConsumingWebEndpointMappingAdapter
- ContentCachingFilter
- EnableWebMvcExtension
- EnableWebMvcExtensionListener
- ExclusiveViewResolverApplicationListener
- HandlerMappingWebEndpointMappingFactory
- HandlerMappingWebEndpointMappingResolver
- HandlerMetadataWebEndpointMappingFactory
- HandlerMethodArgumentResolverAdvice
- InterceptingHandlerMethodProcessor
- LazyCompositeHandlerInterceptor
- LoggingHandlerMethodArgumentResolverAdvice
- LoggingMethodHandlerInterceptor
- LoggingPageRenderContextHandlerInterceptor
- MethodHandlerInterceptor
- PropertyConstants
- RequestBodyAdviceAdapter
- RequestMappingMetadata
- RequestMappingMetadataWebEndpointMappingFactory
- RequestPredicateVisitorAdapter
- ResponseBodyAdviceAdapter
- ReversedProxyHandlerMapping
- RouterFunctionVisitorAdapter
- SpringWebMvcHelper
- StoringRequestBodyArgumentAdvice
- StoringResponseBodyReturnValueAdvice
- ViewResolverUtils
- ViewUtils
- WebMvcExtensionBeanDefinitionRegistrar
- WebMvcExtensionConfiguration
- WebMvcUtils
- WebUtils