Class ImmutableMapPropertySource

java.lang.Object
org.springframework.core.env.PropertySource<T>
org.springframework.core.env.EnumerablePropertySource<Map<String,Object>>
org.springframework.core.env.MapPropertySource
io.microsphere.spring.config.env.ImmutableMapPropertySource

public class ImmutableMapPropertySource extends org.springframework.core.env.MapPropertySource
An immutable implementation of MapPropertySource 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:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.springframework.core.env.PropertySource

    org.springframework.core.env.PropertySource.StubPropertySource
  • Field Summary

    Fields inherited from class org.springframework.core.env.PropertySource

    logger, name, source
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new immutable MapPropertySource with the given name and Map.
  • Method Summary

    Methods inherited from class org.springframework.core.env.MapPropertySource

    containsProperty, getProperty, getPropertyNames

    Methods inherited from class org.springframework.core.env.PropertySource

    equals, getName, getSource, hashCode, named, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ImmutableMapPropertySource

      public ImmutableMapPropertySource(String name, Map source)
      Create a new immutable MapPropertySource with the given name and Map.
      Parameters:
      name - the associated name
      source - the Map source (without null values in order to get consistent MapPropertySource.getProperty(java.lang.String) and MapPropertySource.containsProperty(java.lang.String) behavior)