[ 
https://issues.apache.org/jira/browse/CAMEL-25428?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18124838#comment-18124838
 ] 

Guillaume Nodet commented on CAMEL-25428:
-----------------------------------------

This issue is being investigated by a coding agent (on behalf of gnodet).

Root cause identified: In RouteWatcherReloadStrategy.onRouteReload(), when a 
.java file changes in dev mode, the reload sources collected are (1) existing 
routes from getCamelContext().getRoutes() and (2) the changed .java file plus 
any RELOAD_RESOURCES. However, YAML bean definition files (beans.yaml) are not 
included because they are not route sources and are not tracked in 
RELOAD_RESOURCES. The Java file is recompiled successfully (new class loaded 
into the classloader), but beans.yaml is never re-parsed, so the old bean 
instance remains in the registry and routes continue using the stale bean.

Fix direction: Ensure that YAML files declaring beans are included in the 
reload source set (e.g. by tracking bean-declaring resources via 
BeanFactoryDefinition.getResource() or Model.getCustomBeans() and adding them 
to the sources list in onRouteReload).

_Note: This comment was generated by an AI coding agent and requires manual 
verification._

> camel-jbang - dev mode reload keeps the old instance of a bean whose Java 
> source changed
> ----------------------------------------------------------------------------------------
>
>                 Key: CAMEL-25428
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25428
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-jbang
>            Reporter: Claus Ibsen
>            Assignee: Guillaume Nodet
>            Priority: Major
>
> In dev mode (camel run --dev) a Java bean declared in a YAML beans file is 
> recompiled when its source changes, and the routes reload, but the routes 
> keep calling the old bean instance, so the change never takes effect.
> Reproduce with the quick-start/routes example of camel-jbang-examples 
> (routes.camel.yaml, beans.yaml, Greeter.java, application.properties):
> {noformat}
> camel run routes.camel.yaml beans.yaml Greeter.java application.properties 
> --dev
> {noformat}
> beans.yaml declares the bean:
> {noformat}
> - beans:
>     - name: greeter
>       type: "camel.example.Greeter"
>       properties:
>         greeting: "{{greeter.greeting}}"
> {noformat}
> Change the return statement of Greeter.java, e.g. to {{return greeting + ", " 
> + name + "!!! CHANGED";}}. The log says:
> {noformat}
> RouteWatcherReloadStrategy : Routes reloaded summary (total:1 started:1)
> RouteWatcherReloadStrategy :     Started greeting (timer://greet) (source: 
> routes.camel.yaml:4)
> {noformat}
> but the route goes on logging "Hello, Camel!" from the old Greeter. Nothing 
> says the bean was not replaced.
> Expected: a bean of the beans file whose class changed is created again from 
> the new class on reload (or, if that cannot be done, the reload says that a 
> restart is needed). Verified on 4.23.0-SNAPSHOT.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to