This is an automated email from the ASF dual-hosted git repository.

Croway pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git


The following commit(s) were added to refs/heads/main by this push:
     new 548ee11956d CAMEL-27103: camel-spring-boot - 
typeConverterStatisticsEnabled now enables the statistics
548ee11956d is described below

commit 548ee11956d186a5b6100ea1ac74878b244907f8
Author: Loris Boiteux <[email protected]>
AuthorDate: Thu Nov 19 10:42:56 2026 +0100

    CAMEL-27103: camel-spring-boot - typeConverterStatisticsEnabled now enables 
the statistics
    
    Same issue as fixed for Camel Main in apache/camel#30303: the type converter
    registry is created when the CamelContext is built, and its statistics 
cannot
    be enabled afterwards (Camel 4.7). 
CamelAutoConfiguration.doConfigureCamelContext
    calls camelContext.build() before 
DefaultConfigurationConfigurer.configure(),
    so camel.main.type-converter-statistics-enabled=true had no effect.
    
    The option is now set on the context before build(); config.getMain() is
    already bound at that point.
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../camel/spring/boot/CamelAutoConfiguration.java  |  4 ++
 .../boot/TypeConverterStatisticsEnabledTest.java   | 54 ++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index a957329cd0c..d110a4f3086 100644
--- 
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -152,6 +152,10 @@ public class CamelAutoConfiguration {
 
         // setup startup recorder before building context
         configureStartupRecorder(camelContext, config);
+        // the type converter registry is created by build(), and its 
statistics cannot be enabled afterwards
+        if (config.getMain().isTypeConverterStatisticsEnabled()) {
+            camelContext.setTypeConverterStatisticsEnabled(true);
+        }
 
         camelContext.build();
 
diff --git 
a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/TypeConverterStatisticsEnabledTest.java
 
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/TypeConverterStatisticsEnabledTest.java
new file mode 100644
index 00000000000..7ef7ce6d5c4
--- /dev/null
+++ 
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/TypeConverterStatisticsEnabledTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.spring.boot;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.test.spring.junit6.CamelSpringBootTest;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+
+/**
+ * The type converter registry is created when the CamelContext is built, and 
its statistics cannot be enabled
+ * afterwards, so camel.main.type-converter-statistics-enabled must be applied 
before the build (CAMEL-27103).
+ */
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(classes = { CamelAutoConfiguration.class }, properties = {
+        "camel.main.type-converter-statistics-enabled = true" })
+public class TypeConverterStatisticsEnabledTest {
+
+    @Autowired
+    private CamelContext context;
+
+    @Test
+    public void testTypeConverterStatisticsEnabled() {
+        assertTrue(context.isTypeConverterStatisticsEnabled());
+
+        TypeConverterRegistry.Statistics statistics = 
context.getTypeConverterRegistry().getStatistics();
+        long before = statistics.getAttemptCounter();
+
+        assertEquals(123, context.getTypeConverter().convertTo(int.class, 
"123"));
+
+        assertEquals(before + 1, statistics.getAttemptCounter());
+    }
+}

Reply via email to