Class SpringCloudConfigSource

  • All Implemented Interfaces:
    ConfigSource

    public class SpringCloudConfigSource
    extends Object
    implements ConfigSource
    Configuration source that fetches configuration from Spring Cloud Config Server.

    This source connects to a Spring Cloud Config Server and retrieves configuration for a specific application, profile, and label.

    Example Usage:

    
     // Simple usage
     SpringCloudConfigSource source = new SpringCloudConfigSource(
         "http://config-server:8888", "myapp", "production");
     ConfNG.addSource(source);
     
     // With authentication and custom label
     SpringCloudConfigSource source = SpringCloudConfigSource.builder()
         .serverUrl("http://config-server:8888")
         .application("myapp")
         .profile("production")
         .label("main")
         .username("user")
         .password("secret")
         .build();
     ConfNG.addSource(source);
     
    Since:
    1.1.0
    Author:
    Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
    • Constructor Detail

      • SpringCloudConfigSource

        public SpringCloudConfigSource​(String serverUrl,
                                       String application,
                                       String profile)
        Creates a new Spring Cloud Config source with default settings.
      • SpringCloudConfigSource

        public SpringCloudConfigSource​(String serverUrl,
                                       String application,
                                       String profile,
                                       String label,
                                       String username,
                                       String password,
                                       int connectTimeoutMs,
                                       int readTimeoutMs,
                                       long cacheTimeoutMs,
                                       int priority)
        Creates a new Spring Cloud Config source with custom settings.
      • SpringCloudConfigSource

        public SpringCloudConfigSource​(String serverUrl,
                                       String application,
                                       String profile,
                                       String label,
                                       String username,
                                       String password,
                                       int connectTimeoutMs,
                                       int readTimeoutMs,
                                       long cacheTimeoutMs,
                                       int priority,
                                       int maxRetries,
                                       long retryDelayMs)
        Creates a new Spring Cloud Config source with custom settings including retry configuration.
    • Method Detail

      • getName

        public String getName()
        Description copied from interface: ConfigSource
        Returns the name of this configuration source.
        Specified by:
        getName in interface ConfigSource
        Returns:
        the source name, never null
      • get

        public Optional<String> get​(String key)
        Description copied from interface: ConfigSource
        Retrieves a configuration value for the given key.

        If the key is not found in this source, an empty Optional should be returned. This allows the ConfNG system to try other sources in the resolution chain.

        Specified by:
        get in interface ConfigSource
        Parameters:
        key - the configuration key to look up
        Returns:
        an Optional containing the value if found, empty otherwise
      • getPriority

        public int getPriority()
        Description copied from interface: ConfigSource
        Returns the priority of this configuration source.

        Sources with higher priority values are consulted first in the resolution chain. Default priorities:

        • 100+ - Secret managers and secure sources
        • 80-99 - TestNG parameters and test-specific sources
        • 60-79 - Environment variables
        • 40-59 - System properties
        • 20-39 - Configuration files (JSON, Properties)
        • 0-19 - Default and fallback sources
        Specified by:
        getPriority in interface ConfigSource
        Returns:
        the priority value, higher values have higher priority
      • refresh

        public void refresh()
        Forces a refresh of the cached configuration.