This is an automated email from the ASF dual-hosted git repository.
Croway pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push:
new 981fa308231 camel-spring-boot: fix BindException from non-enumerable
PropertySource on Camel components
981fa308231 is described below
commit 981fa30823162aa76be6589f2b0c1089584909cf
Author: Salvatore Mongiardo <[email protected]>
AuthorDate: Thu Sep 24 13:05:12 2026 +0200
camel-spring-boot: fix BindException from non-enumerable PropertySource on
Camel components
Spring Boot's Binder speculatively walks every nested JavaBean in a
@ConfigurationProperties class when a non-enumerable PropertySource is
present (e.g. Vault, cloud config, or any custom resolver that does not
expose its key set). For Camel component configuration classes that hold
third-party options such as a Jackson ObjectMapper, this walk eventually
reaches a type that cannot be instantiated by the Binder
(JacksonFeatureSet<StreamWriteCapability>) and causes a BindException at
application startup, even when the user has not set any related property.
Fix: add CamelConfigurationPropertiesBindHandlerAdvisor, a
ConfigurationPropertiesBindHandlerAdvisor that intercepts each nested
bind attempt under camel.*. When the target type is a third-party bean
(not java.*, not org.apache.camel.*, not a primitive/enum/array/Map/
Collection) and no property source has a concrete value or a confirmed
descendant key for it, the advisor skips the speculative walk entirely.
Normal binding is unaffected: values set via enumerable sources or via a
non-enumerable source (e.g. #bean:myMapper) are still applied.
The advisor is registered as a static @Bean in CamelAutoConfiguration so
it is available to all @ConfigurationProperties binders in the context.
Resolves the startup failure seen with camel-salesforce-starter and
camel-http-starter on Spring Boot 4.1.1 + Jackson 2.18.x.
---
.../camel/spring/boot/CamelAutoConfiguration.java | 9 ++
...lConfigurationPropertiesBindHandlerAdvisor.java | 86 +++++++++++
.../com/example/springboot/ThirdPartySettings.java | 34 +++++
...figurationPropertiesBindHandlerAdvisorTest.java | 161 +++++++++++++++++++++
4 files changed, 290 insertions(+)
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 a3429047a20..723a0197c72 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
@@ -92,6 +92,15 @@ public class CamelAutoConfiguration {
private static final Logger LOG =
LoggerFactory.getLogger(CamelAutoConfiguration.class);
+ /**
+ * Stops Spring Boot from binding into the internals of third party types
held by the options of the Camel
+ * configuration classes, unless the application configured them.
+ */
+ @Bean
+ static CamelConfigurationPropertiesBindHandlerAdvisor
camelConfigurationPropertiesBindHandlerAdvisor() {
+ return new CamelConfigurationPropertiesBindHandlerAdvisor();
+ }
+
/**
* Spring-aware Camel context for the application. Auto-detects and loads
all routes available in the Spring
* context.
diff --git
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationPropertiesBindHandlerAdvisor.java
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationPropertiesBindHandlerAdvisor.java
new file mode 100644
index 00000000000..8b508c5f20c
--- /dev/null
+++
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationPropertiesBindHandlerAdvisor.java
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+import java.util.Collection;
+import java.util.Map;
+
+import
org.springframework.boot.context.properties.ConfigurationPropertiesBindHandlerAdvisor;
+import org.springframework.boot.context.properties.bind.AbstractBindHandler;
+import org.springframework.boot.context.properties.bind.BindContext;
+import org.springframework.boot.context.properties.bind.BindHandler;
+import org.springframework.boot.context.properties.bind.Bindable;
+import
org.springframework.boot.context.properties.source.ConfigurationPropertyName;
+import
org.springframework.boot.context.properties.source.ConfigurationPropertySource;
+import
org.springframework.boot.context.properties.source.ConfigurationPropertyState;
+
+/**
+ * Stops Spring Boot from binding into the internals of third party types,
such as a Jackson <tt>ObjectMapper</tt>,
+ * held by the options of the Camel configuration classes, unless the
application configured a property below them.
+ * <p/>
+ * Spring Boot binds a nested JavaBean only when a property source has a
property below it. A property source that
+ * cannot list its property names, such as one that looks properties up in a
remote store, cannot tell, so Spring Boot
+ * binds into every nested JavaBean in case it has a property below it. For an
option of a third party type that walks
+ * into the internals of that type, which may fail, and then the application
fails to start although it configured
+ * nothing there.
+ * <p/>
+ * The options of the Camel configuration classes are still bound when the
application configures them, whether as a
+ * value, such as a <tt>#bean:myObjectMapper</tt> reference, or as properties
below them in a property source that can
+ * list its property names. The options of Camel's own types, such as the
nested configuration of a component, are
+ * bound as before.
+ */
+public class CamelConfigurationPropertiesBindHandlerAdvisor implements
ConfigurationPropertiesBindHandlerAdvisor {
+
+ private static final ConfigurationPropertyName CAMEL =
ConfigurationPropertyName.of("camel");
+
+ @Override
+ public BindHandler apply(BindHandler bindHandler) {
+ return new AbstractBindHandler(bindHandler) {
+ @Override
+ public <T> Bindable<T> onStart(ConfigurationPropertyName name,
Bindable<T> target, BindContext context) {
+ if (context.getDepth() > 0 && CAMEL.isAncestorOf(name) &&
isThirdPartyBean(target)
+ && !isConfigured(name, context)) {
+ return null;
+ }
+ return super.onStart(name, target, context);
+ }
+ };
+ }
+
+ private static boolean isThirdPartyBean(Bindable<?> target) {
+ Class<?> type = target.getType().resolve(Object.class);
+ if (type.isPrimitive() || type.isArray() || type.isEnum() ||
Map.class.isAssignableFrom(type)
+ || Collection.class.isAssignableFrom(type)) {
+ return false;
+ }
+ String name = type.getName();
+ return !name.startsWith("java.") &&
!name.startsWith("org.apache.camel.");
+ }
+
+ /**
+ * Whether a property source has a value for the option, or a property
below it for certain.
+ */
+ private static boolean isConfigured(ConfigurationPropertyName name,
BindContext context) {
+ for (ConfigurationPropertySource source : context.getSources()) {
+ if (source.getConfigurationProperty(name) != null
+ || source.containsDescendantOf(name) ==
ConfigurationPropertyState.PRESENT) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git
a/core/camel-spring-boot/src/test/java/com/example/springboot/ThirdPartySettings.java
b/core/camel-spring-boot/src/test/java/com/example/springboot/ThirdPartySettings.java
new file mode 100644
index 00000000000..f90e7fa9e67
--- /dev/null
+++
b/core/camel-spring-boot/src/test/java/com/example/springboot/ThirdPartySettings.java
@@ -0,0 +1,34 @@
+/*
+ * 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 com.example.springboot;
+
+/**
+ * Stands in for a third party JavaBean held by an option of a Camel
configuration class. Deliberately outside the
+ * org.apache.camel packages.
+ */
+public class ThirdPartySettings {
+
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git
a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelConfigurationPropertiesBindHandlerAdvisorTest.java
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelConfigurationPropertiesBindHandlerAdvisorTest.java
new file mode 100644
index 00000000000..b0499cc1f5e
--- /dev/null
+++
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelConfigurationPropertiesBindHandlerAdvisorTest.java
@@ -0,0 +1,161 @@
+/*
+ * 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;
+
+import java.util.Map;
+
+import com.example.springboot.ThirdPartySettings;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import
org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
+import
org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.core.env.PropertySource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+public class CamelConfigurationPropertiesBindHandlerAdvisorTest {
+
+ private static final ObjectMapper MY_MAPPER = new ObjectMapper();
+
+ private final ApplicationContextRunner runner = new
ApplicationContextRunner()
+
.withConfiguration(AutoConfigurations.of(CamelAutoConfiguration.class))
+ .withUserConfiguration(DummyConfiguration.class);
+
+ @Test
+ public void nonEnumerableSourceDoesNotBindIntoThirdPartyTypes() {
+ // without the advisor Spring Boot binds into the internals of the
ObjectMapper, in case the source has a
+ // property there, and fails
+ runner.withInitializer(ctx ->
ctx.getEnvironment().getPropertySources().addLast(nonEnumerable(Map.of())))
+ .run(ctx -> {
+ assertNull(ctx.getStartupFailure());
+ DummyComponentConfiguration config =
ctx.getBean(DummyComponentConfiguration.class);
+ assertNull(config.getObjectMapper());
+ assertNull(config.getConfig().getObjectMapper());
+ });
+ }
+
+ @Test
+ public void nonEnumerableSourceStillBindsConfiguredOptions() {
+ Map<String, Object> values = Map.of(
+ "camel.component.dummy.object-mapper", "myMapper",
+ "camel.component.dummy.config.name", "foo",
+ "camel.component.dummy.config.object-mapper", "myMapper");
+ runner.withInitializer(ctx ->
ctx.getEnvironment().getPropertySources().addLast(nonEnumerable(values)))
+ .run(ctx -> {
+ assertNull(ctx.getStartupFailure());
+ DummyComponentConfiguration config =
ctx.getBean(DummyComponentConfiguration.class);
+ assertSame(MY_MAPPER, config.getObjectMapper());
+ assertEquals("foo", config.getConfig().getName());
+ assertSame(MY_MAPPER,
config.getConfig().getObjectMapper());
+ });
+ }
+
+ @Test
+ public void propertiesBelowThirdPartyTypesAreStillBound() {
+ runner.withPropertyValues("camel.component.dummy.settings.name=foo")
+ .run(ctx -> {
+ assertNull(ctx.getStartupFailure());
+ assertEquals("foo",
ctx.getBean(DummyComponentConfiguration.class).getSettings().getName());
+ });
+ }
+
+ private static PropertySource<Object> nonEnumerable(Map<String, Object>
values) {
+ return new PropertySource<>("nonEnumerable") {
+ @Override
+ public Object getProperty(String name) {
+ return values.get(name);
+ }
+ };
+ }
+
+ @Configuration
+ @EnableConfigurationProperties(DummyComponentConfiguration.class)
+ static class DummyConfiguration {
+ @Bean
+ @ConfigurationPropertiesBinding
+ static ObjectMapperConverter objectMapperConverter() {
+ return new ObjectMapperConverter();
+ }
+ }
+
+ static class ObjectMapperConverter implements Converter<String,
ObjectMapper> {
+ @Override
+ public ObjectMapper convert(String source) {
+ return "myMapper".equals(source) ? MY_MAPPER : null;
+ }
+ }
+
+ @ConfigurationProperties(prefix = "camel.component.dummy")
+ public static class DummyComponentConfiguration {
+ private ObjectMapper objectMapper;
+ private ThirdPartySettings settings;
+ private DummyEndpointConfig config = new DummyEndpointConfig();
+
+ public ObjectMapper getObjectMapper() {
+ return objectMapper;
+ }
+
+ public void setObjectMapper(ObjectMapper objectMapper) {
+ this.objectMapper = objectMapper;
+ }
+
+ public ThirdPartySettings getSettings() {
+ return settings;
+ }
+
+ public void setSettings(ThirdPartySettings settings) {
+ this.settings = settings;
+ }
+
+ public DummyEndpointConfig getConfig() {
+ return config;
+ }
+
+ public void setConfig(DummyEndpointConfig config) {
+ this.config = config;
+ }
+ }
+
+ public static class DummyEndpointConfig {
+ private String name;
+ private ObjectMapper objectMapper;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public ObjectMapper getObjectMapper() {
+ return objectMapper;
+ }
+
+ public void setObjectMapper(ObjectMapper objectMapper) {
+ this.objectMapper = objectMapper;
+ }
+ }
+}