### Local .properties File Override Example Source: https://context7.com/ghdefe/local-overwrite-apollo/llms.txt Override Apollo or application.properties values by creating a local.properties file in the .env/ directory. Keys are matched verbatim. ```properties # .env/local.properties — overrides values coming from Apollo or application.properties demo.name=local-override-value server.port=18080 spring.datasource.url=jdbc:mysql://localhost:3306/dev_db ``` ```java // Any Spring bean picks up the overridden value automatically @Component public class DemoBean { private final String name; @Value("${server.port}") private int port; public DemoBean(@Value("${demo.name}") String name) { this.name = name; } @EventListener(ApplicationReadyEvent.class) public void onReady() { // name → "local-override-value" (from .env/local.properties) // port → 18080 (from .env/local.properties) System.out.println("name=" + name + ", port=" + port); } } ``` -------------------------------- ### Windows-Only Activation Guard Source: https://context7.com/ghdefe/local-overwrite-apollo/llms.txt This example demonstrates the OS check within `PropertySourcesOperator.addPropertySourceToFirst()`. The library only modifies the `Environment` on Windows; on Linux or macOS, it returns early, effectively making it a no-op. ```java // Effective behavior per OS: // Windows → local files loaded, inserted at Environment head // Linux → skipped (log: "current os is: Linux, not window, skip") // macOS → skipped (log: "current os is: Mac OS X, not window, skip") // To verify activation at runtime, enable DEBUG logging: // application.properties: logging.level.com.github.ghdefe=debug // Expected DEBUG output on Windows startup: // [INFO ] LocalPropertiesEnvironmentPostProcessor - postProcessEnvironment add local propertySource // [INFO ] LocalPropertiesPropertySourceFactory - Find Local `.env` Path in C:\projects\my-service\.env // [DEBUG] PropertySourcesOperator - addPropertySourceToFirst: LocalFileComposePropertySource ``` -------------------------------- ### Local .env File Override Example (Environment-Variable Format) Source: https://context7.com/ghdefe/local-overwrite-apollo/llms.txt Override properties using environment-variable style .env files in the .env/ directory. Spring's relaxed binding is used for name mapping. ```properties # .env/local.env — environment-variable style, loaded with relaxed binding DEMO_NAME=env-override-value SERVER_PORT=17070 SPRING_DATASOURCE_URL=jdbc:mysql://localhost:3306/dev_db ``` ```java // Standard @Value injection resolves relaxed-binding names transparently @Component public class EnvDemoBean { @Value("${demo.name}") // resolved from DEMO_NAME via relaxed binding private String name; @Value("${server.port}") // resolved from SERVER_PORT private int port; @EventListener(ApplicationReadyEvent.class) public void onReady() { // name → "env-override-value" // port → 17070 System.out.println("name=" + name + ", port=" + port); } } ``` -------------------------------- ### Spring Boot Auto-Configuration Integration Source: https://context7.com/ghdefe/local-overwrite-apollo/llms.txt This Java code shows a typical Spring Boot application setup. The library's auto-configuration automatically wires up the necessary components, making local overrides active immediately on startup without requiring explicit application code changes. ```java // Priority / ordering summary: // LocalPropertiesEnvironmentPostProcessor → order = -1 (earliest) // LocalPropertiesApplicationContextInitializer → order = 1 // LocalPropertiesBeanFacatoryPostProcessor → order = Ordered.HIGHEST_PRECEDENCE + 1 // No application code is required — auto-configuration wires everything: @SpringBootApplication public class MyServiceApplication { public static void main(String[] args) { SpringApplication.run(MyServiceApplication.class, args); // Local .env/ overrides are active immediately on startup } } ``` -------------------------------- ### Composite Property Source Resolution Source: https://context7.com/ghdefe/local-overwrite-apollo/llms.txt Illustrates how `LocalFileComposePropertySource` aggregates multiple delegate sources and resolves property lookups. The `.env` files are added first, followed by `.properties` files, with `.env` values taking precedence for duplicate keys. ```java // Conceptual resolution order when both local.env and local.properties exist: // 1. local.env files are added first (env-variable format) // 2. local.properties files are added second // → If the same key exists in both, the .env file wins LocalFileComposePropertySource compose = new LocalFileComposePropertySource(); // Delegates added internally by LocalPropertiesPropertySourceFactory: compose.addDelegatePropertySource(new LocalEnvFilePropertySource(envFile)); compose.addDelegatePropertySource(new LocalPropertiesFilePropertySource(propertiesFile)); // Property resolution: Object value = compose.getProperty("demo.name"); // returns first non-null match String[] allKeys = compose.getPropertyNames(); // union of all delegate key sets ``` -------------------------------- ### Register Local Properties to Environment Source: https://context7.com/ghdefe/local-overwrite-apollo/llms.txt This code demonstrates how to programmatically add local property sources to the Spring environment. It ensures that local overrides have the highest priority. ```java // Internal usage (called automatically by the three hook classes) List> sources = LocalPropertiesPropertySourceFactory.getPropertySource(); // sources contains a single LocalFileComposePropertySource that delegates to: // - LocalEnvFilePropertySource for each *.env file found // - LocalPropertiesFilePropertySource for each *.properties file found // Result is then prepended to the environment: MutablePropertySources propertySources = environment.getPropertySources(); sources.forEach(propertySources::addFirst); // → Local file properties now have the highest resolution priority ``` -------------------------------- ### Exclude Local Config Files from Git Source: https://context7.com/ghdefe/local-overwrite-apollo/llms.txt This bash command adds the `.env/` directory to the `.gitignore` file, preventing local override configuration files from being committed to version control. Verify the exclusion using `git status`. ```bash # Run once in the project root: echo "/.env/" >> .gitignore # Verify git status # → .env/ should no longer appear as an untracked directory ``` -------------------------------- ### Add Maven Dependency for local-overwrite-apollo Source: https://context7.com/ghdefe/local-overwrite-apollo/llms.txt Include this dependency in your Spring Boot project's pom.xml to enable the local configuration override functionality. ```xml org.eu.defe local-overwrite-apollo 0.0.6 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.