davsclaus opened a new pull request, #26611:
URL: https://github.com/apache/camel/pull/26611

   ## Description
   
   Implements step 1 of 
[CAMEL-24820](https://issues.apache.org/jira/browse/CAMEL-24820): builder 
inference in bean declarations.
   
   A bean whose class has no public no-arg constructor but a public static 
`builder()` or `newBuilder()` method (Lombok `@Builder`, Immutables, 
LangChain4j, Spring AI, AWS SDK v2, Jackson, protobuf, the JDK `HttpClient`, 
...) is now created via that builder: the properties are set on the builder and 
the bean is created with its `build()` method, or its single public no-arg 
method that returns the type. `builderClass` and `builderMethod` are no longer 
needed for such a class, so a LangChain4j model is declared with only its type 
and properties:
   
   ```yaml
   - beans:
     - name: chatModel
       type: dev.langchain4j.model.ollama.OllamaChatModel
       properties:
         baseUrl: "{{ollama.base.url}}"
         modelName: "{{ollama.model}}"
   ```
   
   ```properties
   camel.beans.chatModel = #class:dev.langchain4j.model.ollama.OllamaChatModel
   camel.beans.chatModel.baseUrl = http://localhost:11434
   camel.beans.chatModel.modelName = qwen2.5
   ```
   
   Covers YAML and XML `beans`, route template local beans, `camel.beans.` in 
Camel Main, and `#class:` values in property binding. The inference lives in 
`PropertyBindingSupport` (`isBuilderOnly`, `newBuilderInstance`, 
`findBuilderMethod`) and is used by `BeanModelHelper` and `BaseMainSupport`.
   
   Rules, so no working declaration changes behaviour:
   - a class with a public no-arg constructor keeps being created with the 
constructor, even if it also has a `builder()`
   - `builderClass`, `factoryMethod`/`factoryBean` and `constructors` take 
precedence when given (also when embedded in the type, `#class:Foo#create('x')`)
   - `builderMethod` can now be set without `builderClass`, to name the method 
of an inferred builder; a builder with no `build()` and several methods 
returning the type fails with a message naming them
   - a property the builder does not take is set on the created bean; an 
unknown property fails naming the property
   
   Also fixes a regression found by the new test: 
`PropertyBindingSupport.setPropertiesOnTarget` rethrew a 
`PropertyBindingException` with its (null) cause, and since the JSpecify change 
in 4.21 (CAMEL-22640) the constructor does `requireNonNull(e)`, so a typo in a 
bean property surfaced as `NullPointerException: e` instead of the property 
name.
   
   Docs: YAML DSL, XML IO DSL, property binding, Camel Main (`camel.beans`), 
bean model metadata, and the 4.23 upgrade guide.
   
   ## Tests
   
   - `core/camel-core`: `BeanModelHelperInferredBuilderTest` (builder(), 
newBuilder() without build(), builderMethod override, constructor wins, factory 
method not inferred, ambiguous builder, no builder, `#class:` via 
`resolveBean`), `RouteTemplateLocalBeanTest#testLocalBeanInferredBuilder`
   - `core/camel-main`: `MainBeansInferredBuilderTest` (`camel.beans.` dot 
properties on the builder, defaults, unknown property)
   - `dsl/camel-yaml-dsl`: `BeansTest` "beans with inferred builder" and the 
unknown-property error
   - Ran the existing `RouteTemplateLocalBeanTest`, 
`PropertyBindingSupport*Test`, `MainBeans*Test`, `BeansTest`, `XmlLoad*Test`, 
and `org.apache.camel.builder.*Template*Test` + `org.apache.camel.model.*Test` 
(296 tests) green; `-Psourcecheck` clean on the four core modules.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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