This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch sbprop in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
commit b308b01c68d51fe7795c3a15a5f02aa9d0d8df1e Author: Claus Ibsen <[email protected]> AuthorDate: Fri Jul 11 15:14:19 2025 +0200 CAMEL-22233: camel-spring-boot - Properties component should eager be configured --- .../src/main/docs/spring-boot.json | 26 +++--- .../camel/spring/boot/CamelAutoConfiguration.java | 44 +++++++++- .../PropertiesComponentConfiguration.java | 2 +- .../PropertiesComponentAutoConfiguration.java | 95 ---------------------- ...rk.boot.autoconfigure.AutoConfiguration.imports | 1 - 5 files changed, 55 insertions(+), 113 deletions(-) diff --git a/core/camel-spring-boot/src/main/docs/spring-boot.json b/core/camel-spring-boot/src/main/docs/spring-boot.json index f139ba3b1f2..f4bd625e757 100644 --- a/core/camel-spring-boot/src/main/docs/spring-boot.json +++ b/core/camel-spring-boot/src/main/docs/spring-boot.json @@ -64,8 +64,8 @@ }, { "name": "camel.component.properties", - "type": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration" + "type": "org.apache.camel.spring.boot.PropertiesComponentConfiguration", + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration" }, { "name": "camel.dataformat", @@ -370,72 +370,72 @@ "name": "camel.component.properties.auto-discover-properties-sources", "type": "java.lang.Boolean", "description": "Whether to automatically discovery instances of PropertiesSource from registry and service factory.", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration", + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration", "defaultValue": true }, { "name": "camel.component.properties.default-fallback-enabled", "type": "java.lang.Boolean", "description": "If false, the component does not attempt to find a default for the key by looking after the colon separator.", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration", + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration", "defaultValue": true }, { "name": "camel.component.properties.encoding", "type": "java.lang.String", "description": "Encoding to use when loading properties file from the file system or classpath. If no encoding has been set, then the properties files is loaded using ISO-8859-1 encoding (latin-1) as documented by java.util.Properties#load(java.io.InputStream)", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration" + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration" }, { "name": "camel.component.properties.environment-variable-mode", "type": "java.lang.Integer", "description": "Sets the OS environment variables mode (0 = never, 1 = fallback, 2 = override). The default mode (override) is to use OS environment variables if present, and override any existing properties. OS environment variable mode is checked before JVM system property mode", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration", + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration", "defaultValue": 2 }, { "name": "camel.component.properties.ignore-missing-location", "type": "java.lang.Boolean", "description": "Whether to silently ignore if a location cannot be located, such as a properties file not found.", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration", + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration", "defaultValue": false }, { "name": "camel.component.properties.initial-properties", "type": "java.lang.String", "description": "Sets initial properties which will be used before any locations are resolved. The option is a java.util.Properties type.", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration" + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration" }, { "name": "camel.component.properties.location", "type": "java.lang.String", "description": "A list of locations to load properties. You can use comma to separate multiple locations. This option will override any default locations and only use the locations from this option.", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration" + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration" }, { "name": "camel.component.properties.nested-placeholder", "type": "java.lang.Boolean", "description": "Whether to support nested property placeholders. A nested placeholder, means that a placeholder, has also a placeholder, that should be resolved (recursively).", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration", + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration", "defaultValue": false }, { "name": "camel.component.properties.override-properties", "type": "java.lang.String", "description": "Sets a special list of override properties that take precedence and will use first, if a property exist. The option is a java.util.Properties type.", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration" + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration" }, { "name": "camel.component.properties.properties-parser", "type": "java.lang.String", "description": "To use a custom PropertiesParser. The option is a org.apache.camel.component.properties.PropertiesParser type.", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration" + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration" }, { "name": "camel.component.properties.system-properties-mode", "type": "java.lang.Integer", "description": "Sets the JVM system property mode (0 = never, 1 = fallback, 2 = override). The default mode (override) is to use system properties if present, and override any existing properties. OS environment variable mode is checked before JVM system property mode", - "sourceType": "org.apache.camel.spring.boot.properties.PropertiesComponentConfiguration", + "sourceType": "org.apache.camel.spring.boot.PropertiesComponentConfiguration", "defaultValue": 2 }, { diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java index de7cee12e8f..989b54a2751 100644 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; @@ -83,7 +84,7 @@ import org.springframework.core.env.MutablePropertySources; @ImportRuntimeHints(CamelRuntimeHints.class) @Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties({CamelConfigurationProperties.class, CamelStartupConditionConfigurationProperties.class}) +@EnableConfigurationProperties({CamelConfigurationProperties.class, CamelStartupConditionConfigurationProperties.class, PropertiesComponentConfiguration.class}) @Import(TypeConversionConfiguration.class) @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public class CamelAutoConfiguration { @@ -383,9 +384,46 @@ public class CamelAutoConfiguration { // (PropertiesComponent extends ServiceSupport) would be used for bean // destruction. And we want Camel to handle the lifecycle. @Bean(destroyMethod = "") - PropertiesComponent properties(PropertiesParser parser) { + PropertiesComponent properties(ApplicationContext applicationContext, PropertiesParser parser, PropertiesComponentConfiguration configuration) { PropertiesComponent pc = new PropertiesComponent(); - pc.setPropertiesParser(parser); + if (configuration.getAutoDiscoverPropertiesSources() != null) { + pc.setAutoDiscoverPropertiesSources(configuration.getAutoDiscoverPropertiesSources()); + } + if (configuration.getDefaultFallbackEnabled() != null) { + pc.setDefaultFallbackEnabled(configuration.getDefaultFallbackEnabled()); + } + if (configuration.getEncoding() != null) { + pc.setEncoding(configuration.getEncoding()); + } + if (configuration.getEnvironmentVariableMode() != null) { + pc.setEnvironmentVariableMode(configuration.getEnvironmentVariableMode()); + } + if (configuration.getSystemPropertiesMode() != null) { + pc.setSystemPropertiesMode(configuration.getSystemPropertiesMode()); + } + if (configuration.getIgnoreMissingLocation() != null) { + pc.setIgnoreMissingLocation(configuration.getIgnoreMissingLocation()); + } + if (configuration.getNestedPlaceholder() != null) { + pc.setNestedPlaceholder(configuration.getNestedPlaceholder()); + } + if (configuration.getLocation() != null) { + pc.setLocation(configuration.getLocation()); + } + if (configuration.getInitialProperties() != null) { + Properties prop = applicationContext.getBean(configuration.getInitialProperties(), Properties.class); + pc.setInitialProperties(prop); + } + if (configuration.getOverrideProperties() != null) { + Properties prop = applicationContext.getBean(configuration.getOverrideProperties(), Properties.class); + pc.setOverrideProperties(prop); + } + if (configuration.getPropertiesParser() != null) { + PropertiesParser pp = applicationContext.getBean(configuration.getPropertiesParser(), PropertiesParser.class); + pc.setPropertiesParser(pp); + } else { + pc.setPropertiesParser(parser); + } return pc; } diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/properties/PropertiesComponentConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/PropertiesComponentConfiguration.java similarity index 99% rename from core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/properties/PropertiesComponentConfiguration.java rename to core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/PropertiesComponentConfiguration.java index b4a6c5ab31c..d65791d8e87 100644 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/properties/PropertiesComponentConfiguration.java +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/PropertiesComponentConfiguration.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.spring.boot.properties; +package org.apache.camel.spring.boot; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/properties/PropertiesComponentAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/properties/PropertiesComponentAutoConfiguration.java deleted file mode 100644 index 2096b68c8af..00000000000 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/properties/PropertiesComponentAutoConfiguration.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.spring.boot.properties; - -import java.util.Properties; -import org.apache.camel.CamelContext; -import org.apache.camel.component.properties.PropertiesComponent; -import org.apache.camel.component.properties.PropertiesParser; -import org.apache.camel.spring.boot.CamelAutoConfiguration; -import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Lazy; - -@Configuration(proxyBeanMethods = false) -@Conditional({ ConditionalOnCamelContextAndAutoConfigurationBeans.class }) -@AutoConfigureAfter(CamelAutoConfiguration.class) -@EnableConfigurationProperties({ PropertiesComponentConfiguration.class }) -public class PropertiesComponentAutoConfiguration { - - @Autowired - private ApplicationContext applicationContext; - @Autowired - private CamelContext camelContext; - - @Lazy - @Bean(name = "properties-component") - @ConditionalOnMissingBean(PropertiesComponent.class) - public PropertiesComponent configurePropertiesComponent(PropertiesComponentConfiguration configuration) - throws Exception { - PropertiesComponent component = new PropertiesComponent(); - component.setCamelContext(camelContext); - - if (configuration.getAutoDiscoverPropertiesSources() != null) { - component.setAutoDiscoverPropertiesSources(configuration.getAutoDiscoverPropertiesSources()); - } - if (configuration.getDefaultFallbackEnabled() != null) { - component.setDefaultFallbackEnabled(configuration.getDefaultFallbackEnabled()); - } - if (configuration.getEncoding() != null) { - component.setEncoding(configuration.getEncoding()); - } - if (configuration.getEnvironmentVariableMode() != null) { - component.setEnvironmentVariableMode(configuration.getEnvironmentVariableMode()); - } - if (configuration.getSystemPropertiesMode() != null) { - component.setSystemPropertiesMode(configuration.getSystemPropertiesMode()); - } - if (configuration.getIgnoreMissingLocation() != null) { - component.setIgnoreMissingLocation(configuration.getIgnoreMissingLocation()); - } - if (configuration.getNestedPlaceholder() != null) { - component.setNestedPlaceholder(configuration.getNestedPlaceholder()); - } - if (configuration.getLocation() != null) { - component.setLocation(configuration.getLocation()); - } - if (configuration.getInitialProperties() != null) { - Properties prop = camelContext.getRegistry().lookupByNameAndType(configuration.getInitialProperties(), - Properties.class); - component.setInitialProperties(prop); - } - if (configuration.getOverrideProperties() != null) { - Properties prop = camelContext.getRegistry().lookupByNameAndType(configuration.getOverrideProperties(), - Properties.class); - component.setOverrideProperties(prop); - } - if (configuration.getPropertiesParser() != null) { - PropertiesParser parser = camelContext.getRegistry() - .lookupByNameAndType(configuration.getPropertiesParser(), PropertiesParser.class); - component.setPropertiesParser(parser); - } - return component; - } -} diff --git a/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 33babc9c09c..251d6b9bcf3 100644 --- a/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -29,7 +29,6 @@ org.apache.camel.spring.boot.cloud.CamelCloudServiceDiscoveryAutoConfiguration org.apache.camel.spring.boot.cloud.CamelCloudServiceFilterAutoConfiguration org.apache.camel.spring.boot.cloud.CamelCloudServiceChooserAutoConfiguration org.apache.camel.spring.boot.cluster.ClusteredRouteControllerAutoConfiguration -org.apache.camel.spring.boot.properties.PropertiesComponentAutoConfiguration org.apache.camel.spring.boot.routecontroller.SupervisingRouteControllerAutoConfiguration org.apache.camel.spring.boot.security.CamelSSLAutoConfiguration org.apache.camel.spring.boot.threadpool.CamelThreadPoolAutoConfiguration
