This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 81724c59c718 CAMEL-27753: camel-support - PropertyBindingSupport 
withPlaceholder(false) and withReference(false) apply to values (#31063)
81724c59c718 is described below

commit 81724c59c7186b777cf4c2cf7594fc9b55e60c9f
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 28 10:15:05 2026 +0100

    CAMEL-27753: camel-support - PropertyBindingSupport withPlaceholder(false) 
and withReference(false) apply to values (#31063)
    
    The withPlaceholder and withReference options of 
PropertyBindingSupport.Builder
    now apply to the values as documented, via reflection and via a property
    configurer. With withPlaceholder(false) a {{...}} placeholder in a value, 
in a
    #property: key or in a #class: value is bound as given. With 
withReference(false)
    a value starting with # (#bean:, #name, #type:, #class:, #property:, 
#autowired,
    #valueAs) is bound as given; PropertyConfigurerSupport.property reads a
    thread-scoped flag set around the configurer call, and the reflection 
fallback
    skips reference resolution too. Defaults and literal mode are unchanged.
    
    Signed-off-by: Claus Ibsen <[email protected]>
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../support/PropertyBindingSupportFlagsTest.java   | 434 +++++++++++++++++++++
 .../camel/support/PropertyBindingSupport.java      | 113 +++++-
 .../component/PropertyConfigurerSupport.java       |   6 +-
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |  14 +
 4 files changed, 545 insertions(+), 22 deletions(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportFlagsTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportFlagsTest.java
new file mode 100644
index 000000000000..5be4206573f8
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportFlagsTest.java
@@ -0,0 +1,434 @@
+/*
+ * 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.support;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.PropertyBindingException;
+import org.apache.camel.spi.PropertyConfigurer;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.support.component.PropertyConfigurerSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The {@link PropertyBindingSupport.Builder} options withPlaceholder, 
withReference, withNesting and withLiteral, for
+ * binding via reflection and via a {@link PropertyConfigurer}.
+ */
+public class PropertyBindingSupportFlagsTest extends ContextTestSupport {
+
+    private static final String GREETING = Greeting.class.getName();
+    private static final String SERVICE = MyService.class.getName();
+
+    private final MyService service = new MyService();
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.getRegistry().bind("myService", service);
+
+        Properties placeholders = new Properties();
+        placeholders.put("myKey", "Hello");
+        placeholders.put("keyName", "value");
+        placeholders.put("beanName", "myService");
+        context.getPropertiesComponent().setInitialProperties(placeholders);
+        return context;
+    }
+
+    // ------------------------------------------------------------------
+    // defaults: placeholders and references are resolved
+    // ------------------------------------------------------------------
+
+    @ParameterizedTest(name = "configurer={0}")
+    @ValueSource(booleans = { false, true })
+    public void placeholderValuesAreResolvedWithDefaults(boolean configurer) {
+        assertEquals("Hello", bindValue(builder(), configurer, "{{myKey}}"));
+        assertEquals("prefix-Hello", bindValue(builder(), configurer, 
"prefix-{{myKey}}"));
+        assertEquals(System.getProperty("java.home"), bindValue(builder(), 
configurer, "{{sys:java.home}}"));
+    }
+
+    @ParameterizedTest(name = "configurer={0}")
+    @ValueSource(booleans = { false, true })
+    public void referenceValuesAreResolvedWithDefaults(boolean configurer) {
+        assertEquals("Hello", bindValue(builder(), configurer, 
"#property:myKey"));
+        assertSame(service, bindValue(builder(), configurer, 
"#bean:myService"));
+        assertSame(service, bindValue(builder(), configurer, "#myService"));
+        assertSame(service, bindValue(builder(), configurer, "#type:" + 
SERVICE));
+        assertEquals(42, bindValue(builder(), configurer, "#valueAs(int):42"));
+
+        Object created = bindValue(builder(), configurer, "#class:" + 
GREETING);
+        assertInstanceOf(Greeting.class, created);
+
+        Object factory = bindValue(builder(), configurer, "#class:" + GREETING 
+ "#of('Hi')");
+        assertInstanceOf(Greeting.class, factory);
+        assertEquals("of:Hi", ((Greeting) factory).getText());
+
+        Object ctr = bindValue(builder(), configurer, "#class:" + GREETING + 
"('{{myKey}}')");
+        assertEquals("Hello", ((Greeting) ctr).getText());
+
+        Target target = new Target();
+        bind(builder(), configurer, target, "service", "#autowired");
+        assertSame(service, target.getService());
+    }
+
+    // ------------------------------------------------------------------
+    // withPlaceholder(false)
+    // ------------------------------------------------------------------
+
+    @ParameterizedTest(name = "configurer={0}")
+    @ValueSource(booleans = { false, true })
+    public void valueIsBoundAsGivenWithPlaceholderOff(boolean configurer) {
+        assertEquals("{{myKey}}", bindValue(builder().withPlaceholder(false), 
configurer, "{{myKey}}"));
+        assertEquals("prefix-{{myKey}}", 
bindValue(builder().withPlaceholder(false), configurer, "prefix-{{myKey}}"));
+        assertEquals("{{sys:java.home}}", 
bindValue(builder().withPlaceholder(false), configurer, "{{sys:java.home}}"));
+    }
+
+    @ParameterizedTest(name = "configurer={0}")
+    @ValueSource(booleans = { false, true })
+    public void placeholderInReferenceIsNotResolvedWithPlaceholderOff(boolean 
configurer) {
+        // placeholders in a #class: value are kept as given
+        Object ctr = bindValue(builder().withPlaceholder(false), configurer, 
"#class:" + GREETING + "('{{myKey}}')");
+        assertEquals("{{myKey}}", ((Greeting) ctr).getText());
+
+        Object factory = bindValue(builder().withPlaceholder(false), 
configurer,
+                "#class:" + GREETING + "#of('{{myKey}}')");
+        assertEquals("of:{{myKey}}", ((Greeting) factory).getText());
+
+        // the key of #property: is not resolved as a placeholder, so there is 
no such property
+        Target target = new Target();
+        PropertyBindingSupport.Builder b = builder().withPlaceholder(false);
+        assertThrows(PropertyBindingException.class, () -> bind(b, configurer, 
target, "value", "#property:{{keyName}}"));
+
+        // references are still resolved
+        assertEquals("Hello", bindValue(builder().withPlaceholder(false), 
configurer, "#property:myKey"));
+        assertSame(service, bindValue(builder().withPlaceholder(false), 
configurer, "#bean:myService"));
+    }
+
+    @ParameterizedTest(name = "configurer={0}")
+    @ValueSource(booleans = { false, true })
+    public void keyIsNotResolvedWithPlaceholderOff(boolean configurer) {
+        Target target = new Target();
+        boolean bound = bind(builder().withPlaceholder(false), configurer, 
target, "{{keyName}}", "Hello");
+        assertFalse(bound);
+        assertNull(target.getValue());
+
+        target = new Target();
+        bound = bind(builder(), configurer, target, "{{keyName}}", "Hello");
+        assertTrue(bound);
+        assertEquals("Hello", target.getValue());
+    }
+
+    // ------------------------------------------------------------------
+    // withReference(false)
+    // ------------------------------------------------------------------
+
+    @ParameterizedTest(name = "configurer={0}")
+    @ValueSource(booleans = { false, true })
+    public void valueIsBoundAsGivenWithReferenceOff(boolean configurer) {
+        String[] values = {
+                "#property:myKey",
+                "#bean:myService",
+                "#myService",
+                "#type:" + SERVICE,
+                "#valueAs(int):42",
+                "#autowired",
+                "#class:" + GREETING,
+                "#class:" + GREETING + "#of('Hi')",
+                "#class:" + GREETING + "('Hi')" };
+        for (String value : values) {
+            assertEquals(value, bindValue(builder().withReference(false), 
configurer, value), value);
+        }
+    }
+
+    @ParameterizedTest(name = "configurer={0}")
+    @ValueSource(booleans = { false, true })
+    public void placeholderIsResolvedWithReferenceOff(boolean configurer) {
+        assertEquals("Hello", bindValue(builder().withReference(false), 
configurer, "{{myKey}}"));
+        // the placeholder is resolved, the reference it resolves to is bound 
as given
+        assertEquals("#bean:myService",
+                bindValue(builder().withReference(false), configurer, 
"#bean:{{beanName}}"));
+    }
+
+    @ParameterizedTest(name = "configurer={0}")
+    @ValueSource(booleans = { false, true })
+    public void valueIsBoundAsGivenWithPlaceholderAndReferenceOff(boolean 
configurer) {
+        PropertyBindingSupport.Builder b = 
builder().withPlaceholder(false).withReference(false);
+        assertEquals("#property:{{keyName}}", bindValue(b, configurer, 
"#property:{{keyName}}"));
+        b = builder().withPlaceholder(false).withReference(false);
+        assertEquals("#class:" + GREETING + "('{{myKey}}')",
+                bindValue(b, configurer, "#class:" + GREETING + 
"('{{myKey}}')"));
+        b = builder().withPlaceholder(false).withReference(false);
+        assertEquals("prefix-{{myKey}}", bindValue(b, configurer, 
"prefix-{{myKey}}"));
+    }
+
+    @Test
+    public void typedOptionIsNotResolvedAsReferenceWithReferenceOff() {
+        // via the configurer a value that starts with # is converted as 
given, which fails for a typed option
+        Target target = new Target();
+        PropertyBindingSupport.Builder b = builder().withReference(false);
+        assertThrows(PropertyBindingException.class, () -> bind(b, true, 
target, "service", "#myService"));
+        assertNull(target.getService());
+
+        // via reflection there is no setter that takes the text
+        Target target2 = new Target();
+        PropertyBindingSupport.Builder b2 = builder().withReference(false);
+        assertThrows(PropertyBindingException.class, () -> bind(b2, false, 
target2, "service", "#myService"));
+        assertNull(target2.getService());
+
+        // with defaults the reference is resolved
+        Target target3 = new Target();
+        bind(builder(), true, target3, "service", "#myService");
+        assertSame(service, target3.getService());
+    }
+
+    @Test
+    public void collectionValueIsBoundAsGivenWithReferenceOff() {
+        Target target = new Target();
+        bind(builder().withReference(false), false, target, "map[foo]", 
"#bean:myService");
+        assertEquals("#bean:myService", target.getMap().get("foo"));
+
+        target = new Target();
+        bind(builder(), false, target, "map[foo]", "#bean:myService");
+        assertSame(service, target.getMap().get("foo"));
+    }
+
+    @Test
+    public void referenceOffDoesNotLeakIntoNextBinding() {
+        assertEquals("#myService", bindValue(builder().withReference(false), 
true, "#myService"));
+        assertFalse(PropertyBindingSupport.isReferenceBindingDisabled());
+
+        // a configurer called directly (outside of a binding with references 
off) resolves the reference
+        assertSame(service, PropertyConfigurerSupport.property(context, 
MyService.class, "#myService"));
+        assertSame(service, bindValue(builder(), true, "#myService"));
+    }
+
+    // ------------------------------------------------------------------
+    // withNesting(false)
+    // ------------------------------------------------------------------
+
+    @ParameterizedTest(name = "configurer={0}")
+    @ValueSource(booleans = { false, true })
+    public void nestedKeyIsSkippedWithNestingOff(boolean configurer) {
+        Target target = new Target();
+        boolean bound = bind(builder().withNesting(false), configurer, target, 
"nested.text", "Hello");
+        assertFalse(bound);
+        assertNull(target.getNested().getText());
+
+        target = new Target();
+        bound = bind(builder(), configurer, target, "nested.text", "Hello");
+        assertTrue(bound);
+        assertEquals("Hello", target.getNested().getText());
+    }
+
+    // ------------------------------------------------------------------
+    // withLiteral(true)
+    // ------------------------------------------------------------------
+
+    @ParameterizedTest(name = "configurer={0}")
+    @ValueSource(booleans = { false, true })
+    public void literalModeIsUnchanged(boolean configurer) {
+        // kept as literal text
+        assertEquals("{{myKey}}", bindValue(builder().withLiteral(true), 
configurer, "{{myKey}}"));
+        Target target = new Target();
+        bind(builder().withLiteral(true), configurer, target, "text", 
"#property:myKey");
+        assertEquals("#property:myKey", target.getText());
+        bind(builder().withLiteral(true), configurer, target, "text", 
"#class:" + GREETING);
+        assertEquals("#class:" + GREETING, target.getText());
+        bind(builder().withLiteral(true), configurer, target, "text", 
"prefix-{{myKey}}");
+        assertEquals("prefix-{{myKey}}", target.getText());
+
+        // still resolved
+        assertSame(service, bindValue(builder().withLiteral(true), configurer, 
"#bean:myService"));
+        assertSame(service, bindValue(builder().withLiteral(true), configurer, 
"#myService"));
+        assertSame(service, bindValue(builder().withLiteral(true), configurer, 
"#type:" + SERVICE));
+        assertEquals(42, bindValue(builder().withLiteral(true), configurer, 
"#valueAs(int):42"));
+
+        target = new Target();
+        bind(builder().withLiteral(true), configurer, target, "service", 
"#autowired");
+        assertSame(service, target.getService());
+    }
+
+    // ------------------------------------------------------------------
+    // helpers
+    // ------------------------------------------------------------------
+
+    private static PropertyBindingSupport.Builder builder() {
+        return PropertyBindingSupport.build();
+    }
+
+    private Object bindValue(PropertyBindingSupport.Builder builder, boolean 
configurer, String value) {
+        Target target = new Target();
+        assertTrue(bind(builder, configurer, target, "value", value), value);
+        return target.getValue();
+    }
+
+    private boolean bind(
+            PropertyBindingSupport.Builder builder, boolean configurer, Target 
target, String key, Object value) {
+        Map<String, Object> props = new LinkedHashMap<>();
+        props.put(key, value);
+        if (configurer) {
+            builder.withConfigurer(new TargetConfigurer());
+        }
+        return builder.bind(context, target, props);
+    }
+
+    public static class MyService {
+    }
+
+    public static class Greeting {
+        private final String text;
+
+        public Greeting() {
+            this(null);
+        }
+
+        public Greeting(String text) {
+            this.text = text;
+        }
+
+        public static Greeting of(String text) {
+            return new Greeting("of:" + text);
+        }
+
+        public String getText() {
+            return text;
+        }
+    }
+
+    public static class Nested {
+        private String text;
+
+        public String getText() {
+            return text;
+        }
+
+        public void setText(String text) {
+            this.text = text;
+        }
+    }
+
+    public static class Target {
+        private Object value;
+        private String text;
+        private MyService service;
+        private Map<String, Object> map;
+        private final Nested nested = new Nested();
+
+        public Object getValue() {
+            return value;
+        }
+
+        public void setValue(Object value) {
+            this.value = value;
+        }
+
+        public String getText() {
+            return text;
+        }
+
+        public void setText(String text) {
+            this.text = text;
+        }
+
+        public MyService getService() {
+            return service;
+        }
+
+        public void setService(MyService service) {
+            this.service = service;
+        }
+
+        public Map<String, Object> getMap() {
+            return map;
+        }
+
+        public void setMap(Map<String, Object> map) {
+            this.map = map;
+        }
+
+        public Nested getNested() {
+            return nested;
+        }
+    }
+
+    /**
+     * A hand-written configurer that converts the values like the generated 
configurers do.
+     */
+    private static class TargetConfigurer implements PropertyConfigurer, 
PropertyConfigurerGetter {
+
+        @Override
+        public boolean configure(CamelContext camelContext, Object target, 
String name, Object value, boolean ignoreCase) {
+            if (target instanceof Target t) {
+                switch (name) {
+                    case "value":
+                        
t.setValue(PropertyConfigurerSupport.property(camelContext, Object.class, 
value));
+                        return true;
+                    case "text":
+                        
t.setText(PropertyConfigurerSupport.property(camelContext, String.class, 
value));
+                        return true;
+                    case "service":
+                        
t.setService(PropertyConfigurerSupport.property(camelContext, MyService.class, 
value));
+                        return true;
+                    default:
+                        return false;
+                }
+            } else if (target instanceof Nested n && "text".equals(name)) {
+                n.setText(PropertyConfigurerSupport.property(camelContext, 
String.class, value));
+                return true;
+            }
+            return false;
+        }
+
+        @Override
+        public Class<?> getOptionType(String name, boolean ignoreCase) {
+            return switch (name) {
+                case "value" -> Object.class;
+                case "text" -> String.class;
+                case "service" -> MyService.class;
+                case "nested" -> Nested.class;
+                default -> null;
+            };
+        }
+
+        @Override
+        public Object getOptionValue(Object target, String name, boolean 
ignoreCase) {
+            if (target instanceof Target t) {
+                return switch (name) {
+                    case "value" -> t.getValue();
+                    case "text" -> t.getText();
+                    case "service" -> t.getService();
+                    case "nested" -> t.getNested();
+                    default -> null;
+                };
+            }
+            return null;
+        }
+    }
+}
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 02ad5ba2b5fa..3dfaa9ad7ec9 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -127,6 +127,10 @@ public final class PropertyBindingSupport {
     // and direct use of this class).
     private static final ThreadLocal<Boolean> LITERAL_OPTION_BINDING = new 
ThreadLocal<>();
 
+    // set while a value is bound via a PropertyConfigurer with reference 
parameters turned off (see
+    // Builder#withReference(boolean)), so PropertyConfigurerSupport#property 
takes a value starting with # as given
+    private static final ThreadLocal<Boolean> REFERENCE_BINDING_DISABLED = new 
ThreadLocal<>();
+
     public static Builder build() {
         return new Builder();
     }
@@ -162,6 +166,18 @@ public final class PropertyBindingSupport {
         return prev;
     }
 
+    /**
+     * Whether the value currently being bound on this thread via a {@link 
PropertyConfigurer} is bound with reference
+     * parameters turned off, see {@link Builder#withReference(boolean)}. The 
configurer then takes a value that starts
+     * with # as given, instead of resolving it as a reference.
+     *
+     * @return true if reference parameters are turned off for the value 
currently being bound on this thread
+     * @since  4.24
+     */
+    public static boolean isReferenceBindingDisabled() {
+        return Boolean.TRUE.equals(REFERENCE_BINDING_DISABLED.get());
+    }
+
     /**
      * Whether the value is kept as literal text when bound in literal mode: a 
value with a property placeholder
      * ({@code {{...}}}), a {@code #class:} value or a {@code #property:} 
value. Plain registry references such as
@@ -625,9 +641,13 @@ public final class PropertyBindingSupport {
             value = text;
         } else {
             try {
-                Object str = resolveValue(camelContext, target, key, text, 
ignoreCase, fluentBuilder,
-                        allowPrivateSetter, reflection, configurer);
-                if (str instanceof String strValue && !literal) {
+                Object str = text;
+                if (reference) {
+                    // resolve #property:, #autowired, #class:, #type:, #bean: 
and #valueAs values
+                    str = resolveValue(camelContext, target, key, text, 
ignoreCase, fluentBuilder,
+                            allowPrivateSetter, placeholder, reflection, 
configurer);
+                }
+                if (placeholder && !literal && str instanceof String strValue) 
{
                     // resolve property placeholders
                     str = camelContext.resolvePropertyPlaceholders(strValue);
                 }
@@ -648,6 +668,15 @@ public final class PropertyBindingSupport {
         // type String gets the literal text
         boolean effReference = reference && !literalValue;
 
+        // a configurer resolves a reference (#...) on its own, so with 
references turned off it is told (thread-scoped)
+        // to take the value as given. The flag is only touched when 
references are off, or when an outer binding on
+        // this thread turned them off
+        Boolean prevReferenceBindingDisabled = 
REFERENCE_BINDING_DISABLED.get();
+        boolean referenceScope = configurer != null && (!reference || 
prevReferenceBindingDisabled != null);
+        if (referenceScope) {
+            setReferenceBindingDisabled(!reference ? Boolean.TRUE : null);
+        }
+
         // okay we are ready to set the value, but the property key
         // can still be complex such as a map/list/array so we need to handle 
them specially than a regular key
         boolean bound = false;
@@ -668,9 +697,9 @@ public final class PropertyBindingSupport {
                     bound = setSimplePropertyViaConfigurer(camelContext, 
target, key, value, ignoreCase, configurer);
                 }
                 if (!bound && reflection) {
-                    // fallback to reflection based
+                    // fallback to reflection based (with references turned 
off, a #... value is not resolved either)
                     bound = setSimplePropertyViaReflection(camelContext, 
target, key, value, fluentBuilder, allowPrivateSetter,
-                            !literalValue && reflection, ignoreCase);
+                            effReference, ignoreCase);
                 }
                 // if the target value is a map type, then we can skip 
reflection
                 // and set the entry
@@ -695,6 +724,10 @@ public final class PropertyBindingSupport {
             throw e;
         } catch (Exception e) {
             throw new PropertyBindingException(target, key, value, e);
+        } finally {
+            if (referenceScope) {
+                setReferenceBindingDisabled(prevReferenceBindingDisabled);
+            }
         }
 
         if (mandatory && !optional && !bound) {
@@ -704,6 +737,14 @@ public final class PropertyBindingSupport {
         return bound;
     }
 
+    private static void setReferenceBindingDisabled(Boolean disabled) {
+        if (disabled != null) {
+            REFERENCE_BINDING_DISABLED.set(disabled);
+        } else {
+            REFERENCE_BINDING_DISABLED.remove();
+        }
+    }
+
     private static boolean isCollectionKey(String name) {
         return name.contains("[") && name.endsWith("]");
     }
@@ -978,14 +1019,23 @@ public final class PropertyBindingSupport {
     private static Object resolveValue(
             CamelContext context, Object target, String name, Object value,
             boolean ignoreCase, boolean fluentBuilder, boolean 
allowPrivateSetter,
-            boolean reflection, PropertyConfigurer configurer)
+            boolean placeholder, boolean reflection, PropertyConfigurer 
configurer)
             throws Exception {
         if (value instanceof String str) {
             if (str.startsWith("#property:")) {
                 String key = str.substring(10);
-                // the key may have property placeholder so resolve those first
-                key = context.resolvePropertyPlaceholders(key);
-                Optional<String> resolved = 
context.getPropertiesComponent().resolveProperty(key);
+                Optional<String> resolved;
+                if (placeholder) {
+                    // the key may have property placeholder so resolve those 
first
+                    key = context.resolvePropertyPlaceholders(key);
+                    resolved = 
context.getPropertiesComponent().resolveProperty(key);
+                } else if (key.contains(PropertiesComponent.PREFIX_TOKEN)) {
+                    // the key is taken as given, and no property has a key 
with a placeholder in it
+                    // (the properties component would resolve the placeholder 
in the key)
+                    resolved = Optional.empty();
+                } else {
+                    resolved = 
context.getPropertiesComponent().resolveProperty(key);
+                }
                 if (resolved.isPresent()) {
                     value = resolved.get();
                 } else {
@@ -995,7 +1045,7 @@ public final class PropertyBindingSupport {
                 value = resolveAutowired(context, target, name, value, 
ignoreCase, fluentBuilder, allowPrivateSetter,
                         reflection, configurer);
             } else {
-                value = resolveBean(context, value);
+                value = doResolveBean(context, value, placeholder);
             }
         }
         return value;
@@ -1651,6 +1701,12 @@ public final class PropertyBindingSupport {
      */
     public static Object newInstanceConstructorParameters(CamelContext 
camelContext, Class<?> type, String parameters)
             throws Exception {
+        return doNewInstanceConstructorParameters(camelContext, type, 
parameters, true);
+    }
+
+    private static Object doNewInstanceConstructorParameters(
+            CamelContext camelContext, Class<?> type, String parameters, 
boolean placeholder)
+            throws Exception {
         // keep quotes as we need to understand the parameter type if its 
boolean,numbers or string (quoted)
         String[] params = StringQuoteHelper.splitSafeQuote(parameters, ',', 
true, true);
         Constructor<?> found = findMatchingConstructor(camelContext, 
type.getConstructors(), params);
@@ -1672,7 +1728,7 @@ public final class PropertyBindingSupport {
                 if (param instanceof String str) {
                     String ref = 
StringHelper.removeLeadingAndEndingQuotes(str);
                     if (ref.startsWith("#")) {
-                        Object bean = resolveBean(camelContext, ref);
+                        Object bean = doResolveBean(camelContext, ref, 
placeholder);
                         if (bean != null) {
                             val = bean;
                         }
@@ -1770,6 +1826,12 @@ public final class PropertyBindingSupport {
     public static Object newInstanceFactoryParameters(
             CamelContext camelContext, Class<?> type, String factoryMethod, 
String parameters)
             throws Exception {
+        return doNewInstanceFactoryParameters(camelContext, type, 
factoryMethod, parameters, true);
+    }
+
+    private static Object doNewInstanceFactoryParameters(
+            CamelContext camelContext, Class<?> type, String factoryMethod, 
String parameters, boolean placeholder)
+            throws Exception {
         // keep quotes as we need to understand the parameter type if its 
boolean,numbers or string (quoted)
         String[] params = StringQuoteHelper.splitSafeQuote(parameters, ',', 
true, true);
         Method found = findMatchingFactoryMethod(camelContext, 
type.getMethods(), factoryMethod, params);
@@ -1791,7 +1853,7 @@ public final class PropertyBindingSupport {
                 if (param instanceof String str) {
                     String ref = removeLeadingAndEndingQuotes(str);
                     if (ref.startsWith("#")) {
-                        Object bean = resolveBean(camelContext, ref);
+                        Object bean = doResolveBean(camelContext, ref, 
placeholder);
                         if (bean != null) {
                             val = bean;
                         }
@@ -2051,6 +2113,10 @@ public final class PropertyBindingSupport {
      * @throws Exception    is thrown if error resolving the bean, or if the 
value is invalid.
      */
     public static Object resolveBean(CamelContext camelContext, Object value) 
throws Exception {
+        return doResolveBean(camelContext, value, true);
+    }
+
+    private static Object doResolveBean(CamelContext camelContext, Object 
value, boolean placeholder) throws Exception {
         if (!(value instanceof String strval)) {
             return value;
         }
@@ -2061,8 +2127,10 @@ public final class PropertyBindingSupport {
         // #property: value is not resolved
         checkLiteralOptionReference(strval);
 
-        // resolve placeholders
-        strval = camelContext.resolvePropertyPlaceholders(strval);
+        if (placeholder) {
+            // resolve placeholders
+            strval = camelContext.resolvePropertyPlaceholders(strval);
+        }
 
         if (strval.startsWith("#class:")) {
             // it's a new class to be created
@@ -2102,7 +2170,7 @@ public final class PropertyBindingSupport {
                 }
                 if (parameters != null) {
                     Class<?> target = factoryClass != null ? factoryClass : 
type;
-                    answer = newInstanceFactoryParameters(camelContext, 
target, factoryMethod, parameters);
+                    answer = doNewInstanceFactoryParameters(camelContext, 
target, factoryMethod, parameters, placeholder);
                 } else {
                     answer = camelContext.getInjector().newInstance(type, 
factoryClass, factoryMethod);
                 }
@@ -2112,7 +2180,7 @@ public final class PropertyBindingSupport {
                 }
             } else if (parameters != null) {
                 // special to support constructor parameters
-                answer = newInstanceConstructorParameters(camelContext, type, 
parameters);
+                answer = doNewInstanceConstructorParameters(camelContext, 
type, parameters, placeholder);
             } else {
                 // a class without a public no-arg constructor but with a 
builder is created via the builder
                 Object builder = newBuilderInstance(type);
@@ -2336,7 +2404,10 @@ public final class PropertyBindingSupport {
         }
 
         /**
-         * Whether reference parameter (syntax starts with #) is in use
+         * Whether reference parameter (syntax starts with #) is in use. When 
turned off, a value starting with # (such
+         * as {@code #bean:name}, {@code #name}, {@code #type:}, {@code 
#class:}, {@code #property:}, {@code #autowired}
+         * or {@code #valueAs(type):value}) is bound as given, both when 
binding via reflection and via a
+         * {@link PropertyConfigurer}.
          */
         public Builder withReference(boolean reference) {
             this.reference = reference;
@@ -2344,7 +2415,9 @@ public final class PropertyBindingSupport {
         }
 
         /**
-         * Whether to use Camels property placeholder to resolve placeholders 
on keys and values
+         * Whether to use Camels property placeholder to resolve placeholders 
on keys and values. When turned off, a key
+         * or value with a property placeholder ({@code {{...}}}) is bound as 
given, and placeholders inside a
+         * {@code #property:} key or a {@code #class:} value are not resolved 
either.
          */
         public Builder withPlaceholder(boolean placeholder) {
             this.placeholder = placeholder;
@@ -2355,8 +2428,8 @@ public final class PropertyBindingSupport {
          * Whether to bind in literal mode, for values computed from message 
content at runtime (for example the option
          * values of a dynamic endpoint). In literal mode a value with a 
property placeholder ({@code {{...}}}), a
          * {@code #class:} value or a {@code #property:} value is bound as 
literal text, and option names are not
-         * resolved as property placeholders. Plain registry references 
({@code #bean:}, {@code #type:}, {@code #name})
-         * are still resolved.
+         * resolved as property placeholders. Plain registry references 
({@code #bean:}, {@code #type:}, {@code #name}),
+         * {@code #autowired} and {@code #valueAs(type):value} are still 
resolved.
          * <p>
          * Literal mode is also on, whatever this option says, while a literal 
option binding scope is active on the
          * current thread, see {@link 
PropertyBindingSupport#isLiteralOptionBinding()}.
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java
index dbaea46c04ad..f2d735a8c799 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java
@@ -24,6 +24,7 @@ import org.apache.camel.NoSuchBeanException;
 import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.support.EndpointHelper;
+import org.apache.camel.support.PropertyBindingSupport;
 import org.apache.camel.util.TimeUtils;
 
 /**
@@ -47,11 +48,12 @@ public abstract class PropertyConfigurerSupport {
      */
     public static <T> T property(CamelContext camelContext, Class<T> type, 
Object value) {
         // if the type is not string based and the value is a bean reference, 
then we need to lookup
-        // the bean from the registry
+        // the bean from the registry (unless reference parameters are turned 
off for the current binding,
+        // then the value is taken as given)
         if (value instanceof String && String.class != type) {
             String text = value.toString();
 
-            if (EndpointHelper.isReferenceParameter(text)) {
+            if (EndpointHelper.isReferenceParameter(text) && 
!PropertyBindingSupport.isReferenceBindingDisabled()) {
                 Object obj;
                 // special for a list where we refer to beans which can be 
either a list or a single element
                 // so use Object.class as type
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 79b27106fa18..f5a9fc5c8a27 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -331,6 +331,20 @@ client library) is now a failed poll, as an exception, and 
the consumer polls ag
 scheduler, it also ended the scheduled task. See the section "camel-core - a 
VirtualMachineError fails the exchange,
 and Camel does not recover from it".
 
+=== camel-support - PropertyBindingSupport withPlaceholder(false) and 
withReference(false) apply to values
+
+The `withPlaceholder` and `withReference` options of 
`PropertyBindingSupport.build()` now apply to the values as
+documented, both when binding via reflection and via a property configurer:
+
+* With `withPlaceholder(false)` a property placeholder in a value (such as 
`+{{myKey}}+` or `+prefix-{{myKey}}+`) is bound
+  as given, and a placeholder in a `#property:` key or a `#class:` value is 
not resolved either. Before, only the keys
+  were left as given.
+* With `withReference(false)` a value that starts with `#` (`#bean:`, `#name`, 
`#type:`, `#class:`, `#property:`,
+  `#autowired` and `#valueAs(type):value`) is bound as given. Before, these 
values were still resolved.
+
+The defaults (both options on) are unchanged. Code that turns these options 
off, and still expects placeholders or
+references in the values to be resolved, must turn them on.
+
 === camel-file - a file lock cluster member waits for an open of the lock file 
that timed out
 
 When an open of the lock file of the file lock cluster service 
(`FileLockClusterService`) takes longer than

Reply via email to