Repository: quarkusio/quarkus
Issue: The datasources are not ready to be consumed when injecting a DS to CamelLifecycle

Injecting a `DataSource` into a `CamelLifecycle` fails with the exception below. I am injecting the datasource to be able to bind it to a name in the Camel registry https://github.com/ppalaga/quarkus/blob/e8253198085073559bf35bfc9a0002ab2d83faec/integration-tests/camel-jdbc/src/main/java/io/quarkus/it/camel/jdbc/CamelLifecycle.java#L38

I assume that should work, @gnodet @lburgazzoli ?

```
[INFO] Running io.quarkus.it.camel.jdbc.CamelJdbcTest
[INFO] H2 database started in TCP server mode
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.916 s <<< FAILURE! - in io.quarkus.it.camel.jdbc.CamelJdbcTest
[ERROR] select  Time elapsed: 0.009 s  <<< ERROR!
org.junit.jupiter.api.extension.TestInstantiationException: TestInstanceFactory [io.quarkus.test.junit.QuarkusTestExtension] failed to instantiate test class [io.quarkus.it.camel.jdbc.CamelJdbcTest]
        at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeTestInstanceFactory(ClassTestDescriptor.java:314)
        at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateTestClass(ClassTestDescriptor.java:289)
        at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateTestClass(ClassTestDescriptor.java:281)
        at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateAndPostProcessTestInstance(ClassTestDescriptor.java:269)
        at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstancesProvider$2(ClassTestDescriptor.java:259)
        at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstancesProvider$3(ClassTestDescriptor.java:263)
        at java.util.Optional.orElseGet(Optional.java:267)
        at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstancesProvider$4(ClassTestDescriptor.java:262)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:98)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:97)
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:68)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$1(NodeTestTask.java:107)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:107)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:75)
        at java.util.ArrayList.forEach(ArrayList.java:1257)
        at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
        at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
        at java.util.ArrayList.forEach(ArrayList.java:1257)
        at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
        at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
        at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
        at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
        at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:142)
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:117)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:383)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:344)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:125)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:417)
Caused by: java.lang.ExceptionInInitializerError
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:121)
        at io.quarkus.test.junit.QuarkusTestExtension.doJavaStart(QuarkusTestExtension.java:236)
        at io.quarkus.test.junit.QuarkusTestExtension.createTestInstance(QuarkusTestExtension.java:302)
        at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeTestInstanceFactory(ClassTestDescriptor.java:299)
        ... 47 more
Caused by: java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl1.<clinit>(Unknown Source)
        ... 56 more
Caused by: org.apache.camel.RuntimeCamelException: java.lang.IllegalStateException: The datasources are not ready to be consumed: the runtime configuration has not been injected yet
        at org.apache.camel.RuntimeCamelException.wrapRuntimeCamelException(RuntimeCamelException.java:52)
        at io.quarkus.camel.core.runtime.support.FastCamelRuntime.doInit(FastCamelRuntime.java:104)
        at io.quarkus.camel.core.runtime.support.FastCamelRuntime.init(FastCamelRuntime.java:51)
        at io.quarkus.camel.core.runtime.CamelTemplate.init(CamelTemplate.java:43)
        at io.quarkus.deployment.steps.CamelInitProcessor$createInitTask17.deploy(Unknown Source)
        ... 57 more
Caused by: java.lang.IllegalStateException: The datasources are not ready to be consumed: the runtime configuration has not been injected yet
        at io.quarkus.agroal.runtime.AbstractDataSourceProducer.checkRuntimeConfig(AbstractDataSourceProducer.java:195)
        at io.quarkus.agroal.runtime.AbstractDataSourceProducer.getDefaultRuntimeConfig(AbstractDataSourceProducer.java:63)
        at io.quarkus.agroal.runtime.DataSourceProducer.createDefaultDataSource(Unknown Source)
        at io.quarkus.agroal.runtime.DataSourceProducer_ProducerMethod_createDefaultDataSource_7c487e3ef869f878aa871e917c94f4d26d5d5c56_Bean.create(Unknown Source)
        at io.quarkus.agroal.runtime.DataSourceProducer_ProducerMethod_createDefaultDataSource_7c487e3ef869f878aa871e917c94f4d26d5d5c56_Bean.create(Unknown Source)
        at io.quarkus.arc.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:86)
        at io.quarkus.arc.AbstractSharedContext.lambda$new$0(AbstractSharedContext.java:33)
        at io.quarkus.arc.ComputingCache$CacheFunction.lambda$apply$0(ComputingCache.java:115)
        at io.quarkus.arc.LazyValue.get(LazyValue.java:42)
        at io.quarkus.arc.ComputingCache.getValue(ComputingCache.java:57)
        at io.quarkus.arc.AbstractSharedContext.get(AbstractSharedContext.java:39)
        at io.quarkus.agroal.runtime.DataSourceProducer_ProducerMethod_createDefaultDataSource_7c487e3ef869f878aa871e917c94f4d26d5d5c56_Bean.get(Unknown Source)
        at io.quarkus.agroal.runtime.DataSourceProducer_ProducerMethod_createDefaultDataSource_7c487e3ef869f878aa871e917c94f4d26d5d5c56_Bean.get(Unknown Source)
        at io.quarkus.it.camel.jdbc.CamelLifecycle_Bean.create(Unknown Source)
        at io.quarkus.it.camel.jdbc.CamelLifecycle_Bean.create(Unknown Source)
        at io.quarkus.arc.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:86)
        at io.quarkus.arc.AbstractSharedContext.lambda$new$0(AbstractSharedContext.java:33)
        at io.quarkus.arc.ComputingCache$CacheFunction.lambda$apply$0(ComputingCache.java:115)
        at io.quarkus.arc.LazyValue.get(LazyValue.java:42)
        at io.quarkus.arc.ComputingCache.getValue(ComputingCache.java:57)
        at io.quarkus.arc.AbstractSharedContext.get(AbstractSharedContext.java:39)
        at io.quarkus.it.camel.jdbc.CamelLifecycle_ClientProxy.delegate(Unknown Source)
        at io.quarkus.it.camel.jdbc.CamelLifecycle_ClientProxy.getContextualInstance(Unknown Source)
        at io.quarkus.it.camel.jdbc.CamelLifecycle_Observer_initializing_efc0f046e9729a2e45b64b01b6ae7f050d5bccd4.notify(Unknown Source)
        at io.quarkus.arc.EventImpl$Notifier.notify(EventImpl.java:244)
        at io.quarkus.arc.EventImpl.fire(EventImpl.java:85)
        at io.quarkus.camel.core.runtime.support.FastCamelRuntime.fireEvent(FastCamelRuntime.java:161)
        at io.quarkus.camel.core.runtime.support.FastCamelRuntime.doInit(FastCamelRuntime.java:85)
        ... 60 more
```

Here is the reproducer ( `cd  integration-tests/camel-jdbc && mvn clean verify` ):
https://github.com/ppalaga/quarkus/commits/190429-camel-jdbc


Changed files:
extensions/agroal/deployment/src/main/java/io/quarkus/agroal/deployment/AgroalProcessor.java

diff --git a/extensions/agroal/deployment/src/main/java/io/quarkus/agroal/deployment/AgroalProcessor.java b/extensions/agroal/deployment/src/main/java/io/quarkus/agroal/deployment/AgroalProcessor.java
index b7043e57fb3..4b91fedeb81 100644
--- a/extensions/agroal/deployment/src/main/java/io/quarkus/agroal/deployment/AgroalProcessor.java
+++ b/extensions/agroal/deployment/src/main/java/io/quarkus/agroal/deployment/AgroalProcessor.java
@@ -27,7 +27,6 @@
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.inject.Default;
 import javax.enterprise.inject.Produces;
-import javax.inject.Singleton;
 
 import org.jboss.jandex.AnnotationInstance;
 import org.jboss.jandex.AnnotationValue;
@@ -195,7 +194,7 @@ public void write(String name, byte[] data) {
         if (agroalBuildTimeConfig.defaultDataSource.driver.isPresent()) {
             MethodCreator defaultDataSourceMethodCreator = classCreator.getMethodCreator("createDefaultDataSource",
                     AgroalDataSource.class);
-            defaultDataSourceMethodCreator.addAnnotation(Singleton.class);
+            defaultDataSourceMethodCreator.addAnnotation(ApplicationScoped.class);
             defaultDataSourceMethodCreator.addAnnotation(Produces.class);
             defaultDataSourceMethodCreator.addAnnotation(Default.class);