davsclaus commented on code in PR #26513:
URL: https://github.com/apache/camel/pull/26513#discussion_r4027033253


##########
core/camel-core-model/src/main/java/org/apache/camel/model/BeanModelHelper.java:
##########
@@ -129,7 +142,7 @@ public static Object newInstance(BeanFactoryDefinition def, 
CamelContext context
         }
 
         // do not set properties when using #type as it uses an existing 
shared bean
-        boolean setProps = !type.startsWith("#type");
+        boolean setProps = type == null || !type.startsWith("#type");

Review Comment:
   Right, and it goes one step further than the description says: `bind()` had 
no builder branch at all, so a `builderClass` bean in a route template never 
worked — without a `type` it fell through to the "invalid type syntax" 
exception, and *with* a `type` it took the class path and silently ignored 
`builderClass`. Pre-existing, but this PR is what makes the schemas promise a 
builder bean without type everywhere, so c692f4bc815f adds the builder branch 
to `bind()`, mirroring `newInstance()` (builder resolved from the class 
resolver, `builderMethod` defaulting to `build`, the properties the builder did 
not take set on the bean, `initMethod`/`destroyMethod`, memorized like the 
script path). Covered by 
`RouteTemplateLocalBeanTest.testLocalBeanBuilderClassWithoutType` (Java DSL) 
and `RouteTemplateTest."create template with builder bean without type"` (YAML) 
— both go through `bind()`.
   
   _Claude Code on behalf of @davsclaus_



##########
dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/BeansDeserializer.java:
##########
@@ -69,14 +69,18 @@ public Object construct(Node node) {
             }
 
             ObjectHelper.notNull(bean.getName(), "The bean name must be set");
-            ObjectHelper.notNull(bean.getType(), "The bean type must be set");
-            if (!bean.getType().startsWith("#class:")) {
-                bean.setType("#class:" + bean.getType());
-            }
-            if (bean.getScriptLanguage() != null || bean.getScript() != null) {
+            boolean script = bean.getScriptLanguage() != null || 
bean.getScript() != null;

Review Comment:
   Aligned in c692f4bc815f: the half-specified guard stays as a plain `if 
(language != null || script != null)`, and the `script` flag is now `language 
!= null && script != null` as in `newInstance()`.
   
   _Claude Code on behalf of @davsclaus_



##########
components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/spring/routebuilder/SpringTemplatedRouteScriptBeanNoTypeTest.xml:
##########
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+            http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+            http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd";>
+
+    <camelContext id="foo" xmlns="http://camel.apache.org/schema/spring";>
+        <routeTemplate id="myTemplate" description="blah blah">
+            <templateParameter name="foo"/>
+            <templateParameter name="bar"/>
+            <route>
+                <from uri="direct:{{foo}}"/>
+                <to uri="bean:{{myScriptBean}}"/>
+                <to uri="bean:{{myBean}}"/>
+                <to uri="mock:{{bar}}"/>
+            </route>
+        </routeTemplate>
+        <templatedRoute routeTemplateRef="myTemplate" routeId="my-route">
+            <parameter name="foo" value="fooVal"/>
+            <parameter name="bar" value="barVal"/>
+            <bean name="myBean" 
type="#class:org.apache.camel.spring.routebuilder.SpringTemplatedRouteScriptBeanNoTypeTest$MySpecialBean">
+                <properties>
+                    <property key="name" value="John"/>
+                </properties>
+            </bean>
+            <!-- a bean created by a script needs no type (class name); the 
XSD must allow it -->
+            <bean name="myScriptBean" scriptLanguage="bean">
+                
<script>org.apache.camel.spring.routebuilder.SpringTemplatedRouteScriptBeanNoTypeTest$MyScriptBean?method=create</script>
+            </bean>
+        </templatedRoute>
+        <route>
+            <from uri="direct:a"/>
+            <to uri="log:foo"/>
+        </route>
+    </camelContext>
+
+</beans>

Review Comment:
   Fixed in c692f4bc815f.
   
   _Claude Code on behalf of @davsclaus_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to