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 d2ef0d979bf CAMEL-20735: camel-jbang - Add support for spring-boot 
datasource
d2ef0d979bf is described below

commit d2ef0d979bfc4d54d4841831c8229bdb788752ca
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sat May 4 12:22:01 2024 +0200

    CAMEL-20735: camel-jbang - Add support for spring-boot datasource
---
 .../org/apache/camel/spi/PropertiesComponent.java  |   9 ++
 .../component/properties/PropertiesComponent.java  |  16 +++
 .../org/apache/camel/main/BaseMainSupport.java     |  52 +--------
 .../java/org/apache/camel/main/MainHelper.java     |  57 +++++++++
 .../modules/ROOT/pages/camel-jbang.adoc            |  40 +++++++
 .../apache/camel/dsl/jbang/core/commands/Run.java  |   4 +
 .../java/org/apache/camel/main/KameletMain.java    |   8 +-
 .../download/AutoConfigureDownloadListener.java    |   4 +-
 .../DependencyDownloaderPropertiesComponent.java   | 128 +++++++++++++++++++++
 .../main/download/KnownDependenciesResolver.java   |  19 ++-
 .../auto-configure/spring.datasource.url.java      |  46 ++++++++
 .../camel-main-known-dependencies.properties       |   1 +
 12 files changed, 330 insertions(+), 54 deletions(-)

diff --git 
a/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java 
b/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java
index 00edeab3834..ef725a8ec01 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java
@@ -114,6 +114,15 @@ public interface PropertiesComponent extends StaticService 
{
      */
     Properties loadProperties(Predicate<String> filter);
 
+    /**
+     * Loads the properties from the default locations and extract properties 
by the given prefix.
+     *
+     * @param  optionPrefix prefix to filter
+     * @param  nested       whether to include nested properties
+     * @return              the properties loaded with option prefix removed.
+     */
+    Properties extractProperties(String optionPrefix, boolean nested);
+
     /**
      * Loads the properties from the default locations and sources filtering 
them out according to a predicate, and maps
      * the key using the key mapper.
diff --git 
a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
 
b/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index bf708f58a22..3ca2daee9ba 100644
--- 
a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ 
b/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -47,6 +47,7 @@ import org.apache.camel.util.FilePathResolver;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.OrderedLocationProperties;
 import org.apache.camel.util.OrderedProperties;
+import org.apache.camel.util.PropertiesHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -236,6 +237,21 @@ public class PropertiesComponent extends ServiceSupport
         return loadProperties(filter, k -> k);
     }
 
+    @Override
+    public Properties extractProperties(String optionPrefix, boolean nested) {
+        Properties answer = new Properties();
+        var map = loadPropertiesAsMap(k -> {
+            boolean accept = k.startsWith(optionPrefix);
+            if (accept && !nested) {
+                int pos = k.lastIndexOf('.');
+                accept = pos == -1 || pos <= optionPrefix.length();
+            }
+            return accept;
+        });
+        answer.putAll(PropertiesHelper.extractProperties(map, optionPrefix));
+        return answer;
+    }
+
     @Override
     public Properties loadProperties(Predicate<String> filter, 
Function<String, String> keyMapper) {
         OrderedLocationProperties prop = new OrderedLocationProperties();
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 645cd0d2638..90a833951f5 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -33,7 +33,6 @@ import java.util.Properties;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.function.Function;
-import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
 import org.apache.camel.CamelConfiguration;
@@ -503,37 +502,10 @@ public abstract class BaseMainSupport extends BaseService 
{
 
     private static void logConfigurationSummary(OrderedLocationProperties 
autoConfiguredProperties) {
         // first log variables
-        doLogConfigurationSummary(autoConfiguredProperties, "Variables 
summary", (k) -> k.startsWith("camel.variable."));
+        MainHelper.logConfigurationSummary(LOG, autoConfiguredProperties, 
"Variables summary",
+                (k) -> k.startsWith("camel.variable."));
         // then log standard options
-        doLogConfigurationSummary(autoConfiguredProperties, 
"Auto-configuration summary", null);
-    }
-
-    private static void doLogConfigurationSummary(
-            OrderedLocationProperties autoConfiguredProperties, String title, 
Predicate<String> filter) {
-        boolean header = false;
-        List<String> toRemove = new ArrayList<>();
-        for (var entry : autoConfiguredProperties.entrySet()) {
-            String k = entry.getKey().toString();
-            if (filter == null || filter.test(k)) {
-                Object v = entry.getValue();
-                String loc = locationSummary(autoConfiguredProperties, k);
-
-                // tone down logging noise for our own internal configurations
-                boolean debug = loc.contains("[camel-main]");
-                if (debug && !LOG.isDebugEnabled()) {
-                    continue;
-                }
-
-                if (!header) {
-                    LOG.info(title);
-                    header = true;
-                }
-
-                sensitiveAwareLogging(k, v, loc, debug);
-                toRemove.add(k);
-            }
-        }
-        toRemove.forEach(autoConfiguredProperties::remove);
+        MainHelper.logConfigurationSummary(LOG, autoConfiguredProperties, 
"Auto-configuration summary", null);
     }
 
     protected void configureStartupRecorder(CamelContext camelContext) {
@@ -2205,7 +2177,7 @@ public abstract class BaseMainSupport extends BaseService 
{
                         header = true;
                     }
 
-                    sensitiveAwareLogging(k, v, loc, debug);
+                    MainHelper.sensitiveAwareLogging(LOG, k, v, loc, debug);
                 }
             }
         } catch (Exception e) {
@@ -2213,22 +2185,6 @@ public abstract class BaseMainSupport extends 
BaseService {
         }
     }
 
-    private static void sensitiveAwareLogging(String k, Object v, String loc, 
boolean debug) {
-        if (SensitiveUtils.containsSensitive(k)) {
-            if (debug) {
-                LOG.debug("    {} {}=xxxxxx", loc, k);
-            } else {
-                LOG.info("    {} {}=xxxxxx", loc, k);
-            }
-        } else {
-            if (debug) {
-                LOG.debug("    {} {}={}", loc, k, v);
-            } else {
-                LOG.info("    {} {}={}", loc, k, v);
-            }
-        }
-    }
-
     private static CamelSagaService resolveLraSagaService(CamelContext 
camelContext) throws Exception {
         CamelSagaService answer = 
camelContext.hasService(CamelSagaService.class);
         if (answer == null) {
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java 
b/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java
index f66c7859712..ea02aeccc3a 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java
@@ -21,14 +21,17 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.LineNumberReader;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Properties;
 import java.util.Set;
 import java.util.function.Function;
+import java.util.function.Predicate;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
@@ -42,12 +45,15 @@ import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.OrderedLocationProperties;
 import org.apache.camel.util.OrderedProperties;
+import org.apache.camel.util.SensitiveUtils;
 import org.apache.camel.util.StopWatch;
 import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.TimeUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.util.LocationHelper.locationSummary;
+
 public final class MainHelper {
     private static final Logger LOG = 
LoggerFactory.getLogger(MainHelper.class);
 
@@ -553,4 +559,55 @@ public final class MainHelper {
         return rc;
     }
 
+    public static void logConfigurationSummary(
+            Logger log, OrderedLocationProperties autoConfiguredProperties,
+            String title, Predicate<String> filter) {
+        if (log == null) {
+            log = LOG;
+        }
+        boolean header = false;
+        List<String> toRemove = new ArrayList<>();
+        for (var entry : autoConfiguredProperties.entrySet()) {
+            String k = entry.getKey().toString();
+            if (filter == null || filter.test(k)) {
+                Object v = entry.getValue();
+                String loc = locationSummary(autoConfiguredProperties, k);
+
+                // tone down logging noise for our own internal configurations
+                boolean debug = loc.contains("[camel-main]");
+                if (debug && !LOG.isDebugEnabled()) {
+                    continue;
+                }
+
+                if (!header) {
+                    log.info(title);
+                    header = true;
+                }
+
+                sensitiveAwareLogging(log, k, v, loc, debug);
+                toRemove.add(k);
+            }
+        }
+        toRemove.forEach(autoConfiguredProperties::remove);
+    }
+
+    public static void sensitiveAwareLogging(Logger log, String k, Object v, 
String loc, boolean debug) {
+        if (log == null) {
+            log = LOG;
+        }
+        if (SensitiveUtils.containsSensitive(k)) {
+            if (debug) {
+                log.debug("    {} {}=xxxxxx", loc, k);
+            } else {
+                log.info("    {} {}=xxxxxx", loc, k);
+            }
+        } else {
+            if (debug) {
+                log.debug("    {} {}={}", loc, k, v);
+            } else {
+                log.info("    {} {}={}", loc, k, v);
+            }
+        }
+    }
+
 }
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index 92b79043902..836d4d897e3 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -2137,6 +2137,46 @@ For example we can customize used 
`org.apache.camel.spi.UuidGenerator` with this
 
 That's it - Camel context will then look up for the instances of 
`org.apache.camel.spi.UuidGenerator` and if one is found, it'll be used by 
Camel.
 
+=== Configuring JDBC DataSources
+
+When using SQL databases, then you would often need to configure a JDBC 
connection pool. You can do this:
+
+- Manually by adding 3rd party JAR dependency on a connection pool, and 
configure this from Java code.
+- *Camel 4.6* Spring Boot style with `spring.datasource.` configuration in 
`application.properties` (uses Hikari connection-pool)
+
+==== Using Spring Boot JDBC data source
+
+In `application.properties` you can set up the datasource such as:
+
+[source,properties]
+----
+spring.datasource.url= 
jdbc:sqlserver://db.example.net:1433;databaseName=test_db
+spring.datasource.username=user
+spring.datasource.password=password
+spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
+----
+
+TIP: Some JDBC drivers are automatic detected by camel-jbang. If not then you 
need to add the JAR dependency manually.
+
+And you can configure the Hikari connection-pool (if needed) such as:
+
+[source,properties]
+----
+spring.datasource.hikari.connection-timeout=30000
+spring.datasource.hikari.maximum-pool-size=10
+spring.datasource.hikari.minimum-idle=5
+spring.datasource.hikari.idle-timeout=600000
+spring.datasource.hikari.max-lifetime=1800000
+spring.datasource.hikari.pool-name=collection-pool
+----
+
+And you can set logging to DEBUG on hikari to see the actual configuration:
+
+[source,properties]
+----
+logging.level.com.zaxxer.hikari = DEBUG
+----
+
 === Debugging
 
 There are two kinds of debugging:
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index cdb3b1ee490..35acf9e6b57 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -535,6 +535,8 @@ public class Run extends CamelCommand {
         writeSetting(main, profileProperties, "camel.jbang.verbose", verbose ? 
"true" : "false");
         // the runtime version of Camel is what is loaded via the catalog
         writeSetting(main, profileProperties, "camel.jbang.camel-version", new 
DefaultCamelCatalog().getCatalogVersion());
+        writeSetting(main, profileProperties, "camel.jbang.springBootVersion", 
springBootVersion);
+        writeSetting(main, profileProperties, "camel.jbang.quarkusVersion", 
quarkusVersion);
 
         // command line arguments
         if (property != null) {
@@ -1084,6 +1086,8 @@ public class Run extends CamelCommand {
             jvmDebugPort = 
parseJvmDebugPort(answer.getProperty("camel.jbang.jvmDebug", 
Integer.toString(jvmDebugPort)));
             camelVersion = answer.getProperty("camel.jbang.camel-version", 
camelVersion);
             kameletsVersion = 
answer.getProperty("camel.jbang.kameletsVersion", kameletsVersion);
+            springBootVersion = 
answer.getProperty("camel.jbang.springBootVersion", springBootVersion);
+            quarkusVersion = answer.getProperty("camel.jbang.quarkusVersion", 
quarkusVersion);
             gav = answer.getProperty("camel.jbang.gav", gav);
             stub = answer.getProperty("camel.jbang.stub", stub);
             exclude = answer.getProperty("camel.jbang.exclude", exclude);
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index 477c84a3819..d66bc292903 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -45,6 +45,7 @@ import 
org.apache.camel.main.download.DependencyDownloaderComponentResolver;
 import org.apache.camel.main.download.DependencyDownloaderDataFormatResolver;
 import org.apache.camel.main.download.DependencyDownloaderKamelet;
 import org.apache.camel.main.download.DependencyDownloaderLanguageResolver;
+import org.apache.camel.main.download.DependencyDownloaderPropertiesComponent;
 import 
org.apache.camel.main.download.DependencyDownloaderPropertiesFunctionResolver;
 import 
org.apache.camel.main.download.DependencyDownloaderPropertyBindingListener;
 import org.apache.camel.main.download.DependencyDownloaderResourceLoader;
@@ -569,7 +570,10 @@ public class KameletMain extends MainCommandLineSupport {
                 answer.addService(new CommandLineDependencyDownloader(answer, 
dependencies.toString()));
             }
 
-            KnownDependenciesResolver knownDeps = new 
KnownDependenciesResolver(answer);
+            String springBootVersion = (String) 
getInitialProperties().get("camel.jbang.springBootVersion");
+            String quarkusVersion = (String) 
getInitialProperties().get("camel.jbang.quarkusVersion");
+
+            KnownDependenciesResolver knownDeps = new 
KnownDependenciesResolver(answer, springBootVersion, quarkusVersion);
             knownDeps.loadKnownDependencies();
             DependencyDownloaderPropertyBindingListener listener
                     = new DependencyDownloaderPropertyBindingListener(answer, 
knownDeps);
@@ -611,6 +615,8 @@ public class KameletMain extends MainCommandLineSupport {
             
answer.getCamelContextExtension().getRegistry().bind(DownloadModelineParser.class.getSimpleName(),
                     new DownloadModelineParser(answer));
 
+            answer.addService(new 
DependencyDownloaderPropertiesComponent(answer, knownDeps, silent));
+
             // reloader
             if (sourceDir != null) {
                 if (console || health) {
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/AutoConfigureDownloadListener.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/AutoConfigureDownloadListener.java
index a03bb9ac695..6b19e4cf50c 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/AutoConfigureDownloadListener.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/AutoConfigureDownloadListener.java
@@ -93,7 +93,7 @@ public class AutoConfigureDownloadListener implements 
DownloadListener, CamelCon
 
     protected void autoConfigure(String artifactId) {
         // is there any special auto configuration scripts?
-        InputStream is = getClass().getResourceAsStream("/auto-configure/" + 
artifactId + ".joor");
+        InputStream is = getClass().getResourceAsStream("/auto-configure/" + 
artifactId + ".java");
         if (is != null) {
             try {
                 // ensure java-joor is downloaded
@@ -102,7 +102,7 @@ public class AutoConfigureDownloadListener implements 
DownloadListener, CamelCon
                 downloader.downloadHiddenDependency("org.apache.camel", 
"camel-joor", camelContext.getVersion());
                 // execute script via java-joor
                 String script = IOHelper.loadText(is);
-                Language lan = camelContext.resolveLanguage("joor");
+                Language lan = camelContext.resolveLanguage("java");
                 Expression exp = lan.createExpression(script);
                 Object out = exp.evaluate(new DefaultExchange(camelContext), 
Object.class);
                 if (ObjectHelper.isNotEmpty(out)) {
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderPropertiesComponent.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderPropertiesComponent.java
new file mode 100644
index 00000000000..db35c74990e
--- /dev/null
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderPropertiesComponent.java
@@ -0,0 +1,128 @@
+/*
+ * 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.main.download;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Expression;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.CamelEvent;
+import org.apache.camel.spi.Language;
+import org.apache.camel.support.DefaultExchange;
+import org.apache.camel.support.SimpleEventNotifierSupport;
+import org.apache.camel.support.service.ServiceSupport;
+import org.apache.camel.tooling.maven.MavenGav;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DependencyDownloaderPropertiesComponent extends ServiceSupport {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(DependencyDownloaderPropertiesComponent.class);
+
+    private final CamelContext camelContext;
+    private final KnownDependenciesResolver knownDependenciesResolver;
+    private final DependencyDownloader downloader;
+    private final boolean silent;
+    private Properties properties;
+
+    public DependencyDownloaderPropertiesComponent(CamelContext camelContext,
+                                                   KnownDependenciesResolver 
knownDependenciesResolver,
+                                                   boolean silent) {
+        this.camelContext = camelContext;
+        this.downloader = camelContext.hasService(DependencyDownloader.class);
+        this.knownDependenciesResolver = knownDependenciesResolver;
+        this.silent = silent;
+    }
+
+    @Override
+    protected void doBuild() throws Exception {
+        camelContext.getManagementStrategy().addEventNotifier(new 
SimpleEventNotifierSupport() {
+            @Override
+            public void notify(CamelEvent event) throws Exception {
+                // scan properties and detect dependencies to download and 
services to auto-configure
+                properties = 
camelContext.getPropertiesComponent().loadProperties();
+                resolveKnownDependencies();
+                autoConfigureServices();
+            }
+
+            @Override
+            public boolean isEnabled(CamelEvent event) {
+                return event instanceof 
CamelEvent.CamelContextInitializingEvent;
+            }
+        });
+    }
+
+    protected void autoConfigureServices() {
+        for (String key : properties.stringPropertyNames()) {
+            autoConfigure(key);
+        }
+    }
+
+    protected void resolveKnownDependencies() {
+        for (String key : properties.stringPropertyNames()) {
+            // check both key and values
+            String value = properties.getProperty(key);
+            MavenGav gav = knownDependenciesResolver.mavenGavForClass(key);
+            if (gav != null) {
+                downloadLoader(gav.getGroupId(), gav.getArtifactId(), 
gav.getVersion());
+            }
+            gav = knownDependenciesResolver.mavenGavForClass(value);
+            if (gav != null) {
+                downloadLoader(gav.getGroupId(), gav.getArtifactId(), 
gav.getVersion());
+            }
+        }
+    }
+
+    private void downloadLoader(String groupId, String artifactId, String 
version) {
+        if (!downloader.alreadyOnClasspath(groupId, artifactId, version)) {
+            downloader.downloadDependency(groupId, artifactId, version);
+        }
+    }
+
+    protected void autoConfigure(String key) {
+        var config = new org.apache.camel.util.OrderedLocationProperties();
+        config.putAll("camel-main", 
camelContext.getPropertiesComponent().loadProperties());
+
+        // is there any special auto configuration scripts?
+        InputStream is = getClass().getResourceAsStream("/auto-configure/" + 
key + ".java");
+        if (is != null) {
+            try {
+                // ensure java-joor is downloaded
+                DependencyDownloader downloader = 
camelContext.hasService(DependencyDownloader.class);
+                // these are extra dependencies used in special use-case so 
download as hidden
+                downloader.downloadHiddenDependency("org.apache.camel", 
"camel-joor", camelContext.getVersion());
+                // execute script via java-joor
+                String script = IOHelper.loadText(is);
+                Language lan = camelContext.resolveLanguage("java");
+                Expression exp = lan.createExpression(script);
+                Object out = exp.evaluate(new DefaultExchange(camelContext), 
Object.class);
+                if (ObjectHelper.isNotEmpty(out)) {
+                    LOG.info("{}", out);
+                }
+            } catch (Exception e) {
+                throw RuntimeCamelException.wrapRuntimeException(e);
+            } finally {
+                IOHelper.close(is);
+            }
+        }
+    }
+
+}
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KnownDependenciesResolver.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KnownDependenciesResolver.java
index 68ff41c456b..0879be27a96 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KnownDependenciesResolver.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KnownDependenciesResolver.java
@@ -28,9 +28,13 @@ public final class KnownDependenciesResolver {
 
     private final Map<String, String> mappings = new HashMap<>();
     private final CamelContext camelContext;
+    private final String springBootVersion;
+    private final String quarkusVersion;
 
-    public KnownDependenciesResolver(CamelContext camelContext) {
+    public KnownDependenciesResolver(CamelContext camelContext, String 
springBootVersion, String quarkusVersion) {
         this.camelContext = camelContext;
+        this.springBootVersion = springBootVersion;
+        this.quarkusVersion = quarkusVersion;
     }
 
     public void loadKnownDependencies() {
@@ -61,10 +65,19 @@ public final class KnownDependenciesResolver {
     }
 
     public MavenGav mavenGavForClass(String className) {
+        MavenGav answer = null;
         String gav = mappings.get(className);
         if (gav != null) {
-            return MavenGav.parseGav(gav, camelContext.getVersion());
+            answer = MavenGav.parseGav(gav, camelContext.getVersion());
         }
-        return null;
+        if (answer != null) {
+            String v = answer.getVersion();
+            if (springBootVersion != null && 
"${spring-boot-version}".equals(v)) {
+                answer.setVersion(springBootVersion);
+            } else if (quarkusVersion != null && 
"${quarkus-version}".equals(v)) {
+                answer.setVersion(quarkusVersion);
+            }
+        }
+        return answer;
     }
 }
diff --git 
a/dsl/camel-kamelet-main/src/main/resources/auto-configure/spring.datasource.url.java
 
b/dsl/camel-kamelet-main/src/main/resources/auto-configure/spring.datasource.url.java
new file mode 100644
index 00000000000..b4cfd8fee19
--- /dev/null
+++ 
b/dsl/camel-kamelet-main/src/main/resources/auto-configure/spring.datasource.url.java
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+var answer = "";
+var registry = context.getRegistry();
+answer = "Auto-configuring spring-datasource";
+
+var p = new org.springframework.boot.autoconfigure.jdbc.DataSourceProperties();
+p.setBeanClassLoader(context.getApplicationContextClassLoader());
+
+var set = new org.apache.camel.util.OrderedLocationProperties();
+var config = new org.apache.camel.util.OrderedLocationProperties();
+var hikari = new org.apache.camel.util.OrderedLocationProperties();
+// hikari is the default connection-pool used by spring-boot
+hikari.putAll("camel-jbang", 
context.getPropertiesComponent().extractProperties("spring.datasource.hikari.", 
false));
+config.putAll("camel-jbang", 
context.getPropertiesComponent().extractProperties("spring.datasource.", 
false));
+
+org.apache.camel.main.MainHelper.setPropertiesOnTarget(context, p, config, 
"spring.datasource.", true, true, set);
+
+var name = p.getName() != null ? p.getName() : "springDataSource";
+var ds = p.initializeDataSourceBuilder().build();
+
+// configure hikari connection-pool specific options
+org.apache.camel.main.MainHelper.setPropertiesOnTarget(context, ds, hikari, 
"spring.datasource.hikari.", true, true, set);
+
+// bind to registry
+registry.bind(name, ds);
+
+// log summary to see what was configured
+org.apache.camel.main.MainHelper.logConfigurationSummary(null, set, "Spring 
DataSource (" + name + ")", null);
+
+return answer;
\ No newline at end of file
diff --git 
a/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties
 
b/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties
index 45065193433..940b4cd9cc3 100644
--- 
a/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties
+++ 
b/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties
@@ -35,3 +35,4 @@ META-INF/services/org/apache/camel/micrometer-prometheus = 
camel:micrometer-prom
 META-INF/services/org/apache/camel/cron/cron-service = camel:quartz
 META-INF/services/org/apache/camel/platform-http/jolokia = 
camel:camel-platform-http-jolokia
 org.apache.camel.component.activemq.ActiveMQComponent\:embedded\=true = 
org.apache.activemq:activemq-broker:5.18.4
+spring.datasource.url = 
org.springframework.boot:spring-boot-starter-jdbc:${spring-boot-version}
\ No newline at end of file

Reply via email to