[ 
https://issues.apache.org/jira/browse/CAMEL-25528?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen updated CAMEL-25528:
--------------------------------
    Fix Version/s: 4.23.0
                   4.22.2

> camel-jbang - camel run ignores camel.jbang.dependencies in a properties file 
> given on the command line, such as camel/application.properties
> ---------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-25528
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25528
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-jbang
>    Affects Versions: 4.22.1
>            Reporter: Federico Mariani
>            Assignee: Federico Mariani
>            Priority: Minor
>             Fix For: 4.22.2, 4.23.0
>
>
> *Problem*
> {{camel run}} reads {{camel.jbang.dependencies}} (and 
> {{camel.jbang.dependencies.main}} / {{.spring-boot}} / {{.quarkus}}) only 
> from the profile properties: {{application.properties}} (and 
> {{application-<profile>.properties}}) of the current directory, or of 
> {{--source-dir}}. A properties file given explicitly on the command line, or 
> with {{--properties}}, is only used for property placeholders: the 
> dependencies declared in it are silently ignored, with no warning.
> So a project laid out with the routes and their properties in a subfolder 
> works with {{camel run camel}} (the directory runs as {{--source-dir}}, so 
> {{camel/application.properties}} is the profile file), but not with {{camel 
> run camel/*.yaml camel/application.properties}} from the same place.
> The runtime still downloads jars on demand for the classes in 
> {{camel-main-known-dependencies.properties}} and the other known-dependencies 
> tables (e.g. {{org.postgresql.ds.PGSimpleDataSource}}), so some setups work 
> by accident and hide the problem. Beans whose class is not mapped fail with 
> {{ClassNotFoundException}}, for example the Spring transaction manager and 
> the Spring transaction policy of a transacted route.
> We found this while evaluating AI coding agents on legacy-to-Camel 
> migrations: the agents declare {{camel.jbang.dependencies}} in 
> {{camel/application.properties}}, as documented, run {{camel run camel/*.yaml 
> camel/application.properties}} from the project root, and get up to 27 
> {{ClassNotFoundException}} per attempt before they find a workaround 
> ({{--dep}}).
> *Reproduction*
> {{camel/routes.camel.yaml}}:
> {code:yaml}
> - beans:
>     - name: myDataSource
>       type: org.springframework.jdbc.datasource.DriverManagerDataSource
>       properties:
>         url: jdbc:h2:mem:demo
>     - name: txManager
>       type: org.springframework.jdbc.datasource.DataSourceTransactionManager
>       properties:
>         dataSource: "#bean:myDataSource"
> - route:
>     from:
>       uri: timer:tick
>       parameters:
>         repeatCount: 1
>       steps:
>         - log: "Transaction manager created"
> {code}
> {{camel/application.properties}}:
> {code}
> camel.jbang.dependencies=camel:sql
> {code}
> From the parent directory of {{camel}}:
> {code}
> camel run camel/routes.camel.yaml camel/application.properties
> {code}
> *Expected:* camel-sql (and so spring-jdbc) is on the classpath, as with 
> {{camel run camel}} or {{camel run camel/routes.camel.yaml --dep=camel:sql}}.
> *Actual:* {{Error creating bean: myDataSource ... 
> java.lang.ClassNotFoundException: 
> org.springframework.jdbc.datasource.DriverManagerDataSource}}; 
> {{camel.jbang.dependencies}} is ignored without any message. ({{camel run 
> camel}} and {{camel run camel/routes.camel.yaml --dep=camel:sql}} both start 
> and log "Transaction manager created".)
> *Proposal*
> # {{camel run}} adds the dependencies ({{camel.jbang.dependencies}} and the 
> variant of the runtime in use) of the local properties files given on the 
> command line or with {{--properties}}, after the ones of the profile 
> properties (which are not read twice) and the {{--dep}} ones. Remote files 
> ({{github:}}, {{classpath:}}...) are skipped. The other {{camel.jbang.*}} 
> keys keep being read from the profile properties only.
> # Map the common Spring transaction classes in 
> {{camel-main-known-dependencies.properties}}, so a transacted route's beans 
> resolve on demand: {{DataSourceTransactionManager}}, 
> {{JdbcTransactionManager}} and {{DriverManagerDataSource}} to {{camel:sql}} 
> (spring-jdbc), {{PlatformTransactionManager}}, {{TransactionTemplate}} and 
> {{org.apache.camel.spring.spi.SpringTransactionPolicy}} to {{camel:spring}} 
> (spring-tx).
> # Document where {{camel.jbang.dependencies}} is read from.
> Related: CAMEL-22673 (dependencies in a non-profile {{--properties}} file not 
> picked up, closed as Information Provided).



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

Reply via email to