Package io.microsphere.spring.config.env
Class ImmutableMapPropertySource
- java.lang.Object
-
- org.springframework.core.env.PropertySource<T>
-
- org.springframework.core.env.EnumerablePropertySource<java.util.Map<java.lang.String,java.lang.Object>>
-
- org.springframework.core.env.MapPropertySource
-
- io.microsphere.spring.config.env.ImmutableMapPropertySource
-
public class ImmutableMapPropertySource extends org.springframework.core.env.MapPropertySource
An immutable implementation ofMapPropertySource
that ensures the underlying map remains unmodifiable.This class is useful in scenarios where the configuration properties should be protected from further modifications after initialization. It wraps the provided source map into an unmodifiable map using
Collections.unmodifiableMap(Map)
.Example Usage
Map<String, Object> source = new HashMap<>(); source.put("key1", "value1"); source.put("key2", 42); ImmutableMapPropertySource propertySource = new ImmutableMapPropertySource("mySource", source); // The following operations will throw UnsupportedOperationException try { propertySource.getPropertySources().addLast(new CustomPropertySource()); } catch (UnsupportedOperationException e) { // Expected exception }
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
MapPropertySource
,Collections.unmodifiableMap(Map)
-
-
Constructor Summary
Constructors Constructor Description ImmutableMapPropertySource(java.lang.String name, java.util.Map source)
Create a new immutableMapPropertySource
with the given name andMap
.
-
-
-
Constructor Detail
-
ImmutableMapPropertySource
public ImmutableMapPropertySource(java.lang.String name, java.util.Map source)
Create a new immutableMapPropertySource
with the given name andMap
.- Parameters:
name
- the associated namesource
- the Map source (withoutnull
values in order to get consistentMapPropertySource.getProperty(java.lang.String)
andMapPropertySource.containsProperty(java.lang.String)
behavior)
-
-