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

fmariani 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 cbdfedb7870 Simplify how Virtual Threads are handled
cbdfedb7870 is described below

commit cbdfedb787074f12fd85351930ac8a955c8225f9
Author: Croway <[email protected]>
AuthorDate: Mon Dec 15 12:11:03 2025 +0100

    Simplify how Virtual Threads are handled
---
 .github/workflows/pr-build-main.yml                |  2 -
 ...ormHttpMultipleExecutorsVirtualThreadsTest.java |  3 ++
 core/camel-spring-boot/pom.xml                     | 51 +---------------------
 ...CamelVirtualThreadEnvironmentPostProcessor.java | 14 +++++-
 .../src/main/resources/META-INF/spring.factories   |  3 ++
 .../src/main/resources21/META-INF/spring.factories | 19 --------
 .../camel/spring/boot/CamelVirtualThreadsTest.java |  5 ---
 tests/camel-itest-spring-boot/pom.xml              | 22 ++++++++++
 8 files changed, 42 insertions(+), 77 deletions(-)

diff --git a/.github/workflows/pr-build-main.yml 
b/.github/workflows/pr-build-main.yml
index 2b8a37d4344..73db087b5b9 100644
--- a/.github/workflows/pr-build-main.yml
+++ b/.github/workflows/pr-build-main.yml
@@ -57,5 +57,3 @@ jobs:
         skip-mvnd-install: 'false'
         github-repo: apache/camel-spring-boot
         artifact-upload-suffix: java-${{ matrix.java }}
-      env:
-        MVND_OPTS: -pl !tests/camel-itest-spring-boot
diff --git 
a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpMultipleExecutorsVirtualThreadsTest.java
 
b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpMultipleExecutorsVirtualThreadsTest.java
index 9bcc715bfea..1a4e5456410 100644
--- 
a/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpMultipleExecutorsVirtualThreadsTest.java
+++ 
b/components-starter/camel-platform-http-starter/src/test/java/org/apache/camel/component/platform/http/springboot/SpringBootPlatformHttpMultipleExecutorsVirtualThreadsTest.java
@@ -21,6 +21,8 @@ import org.apache.camel.spring.boot.CamelAutoConfiguration;
 import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
 import org.assertj.core.api.Assertions;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnJre;
+import org.junit.jupiter.api.condition.JRE;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import 
org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientAutoConfiguration;
@@ -43,6 +45,7 @@ import java.util.concurrent.Executor;
         PlatformHttpComponentAutoConfiguration.class, 
SpringBootPlatformHttpAutoConfiguration.class },
     properties = "spring.threads.virtual.enabled=true")
 @EnableScheduling
+@DisabledOnJre({JRE.JAVA_17, JRE.JAVA_18, JRE.JAVA_19, JRE.JAVA_20})
 public class SpringBootPlatformHttpMultipleExecutorsVirtualThreadsTest extends 
PlatformHttpBase {
 
     private static final String THREAD_PREFIX = "myThread-";
diff --git a/core/camel-spring-boot/pom.xml b/core/camel-spring-boot/pom.xml
index dcbdbd07e04..4cf3d46c9b2 100644
--- a/core/camel-spring-boot/pom.xml
+++ b/core/camel-spring-boot/pom.xml
@@ -280,18 +280,6 @@
                         <artifactId>maven-compiler-plugin</artifactId>
                         <version>${maven-compiler-plugin-version}</version>
                         <executions>
-                            <execution>
-                                <id>compile-java-21</id>
-                                <phase>compile</phase>
-                                <goals>
-                                    <goal>compile</goal>
-                                </goals>
-                                <configuration>
-                                    <release>21</release>
-                                    
<compileSourceRoots>${project.basedir}/src/main/java21</compileSourceRoots>
-                                    
<multiReleaseOutput>true</multiReleaseOutput>
-                                </configuration>
-                            </execution>
                             <execution>
                                 <id>testCompile-java-21</id>
                                 <phase>test-compile</phase>
@@ -306,51 +294,16 @@
                         </executions>
                     </plugin>
 
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-jar-plugin</artifactId>
-                        <configuration>
-                            <archive>
-                                <manifestEntries>
-                                    <Multi-Release>true</Multi-Release>
-                                </manifestEntries>
-                            </archive>
-                        </configuration>
-                    </plugin>
-
-                    <!-- Add resources21 folder when building with JDK 21 -->
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-resources-plugin</artifactId>
-                        <executions>
-                            <execution>
-                                <id>copy-resources21</id>
-                                <phase>process-resources</phase>
-                                <goals>
-                                    <goal>copy-resources</goal>
-                                </goals>
-                                <configuration>
-                                    
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
-                                    <resources>
-                                        <resource>
-                                            
<directory>${basedir}/src/main/resources21</directory>
-                                        </resource>
-                                    </resources>
-                                </configuration>
-                            </execution>
-                        </executions>
-                    </plugin>
-
                     <!-- Configure surefire to run JDK 21 specific tests -->
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-surefire-plugin</artifactId>
                         <version>${maven-surefire-plugin-version}</version>
                         <configuration>
-                            <!-- Set virtual thread properties only for these 
specific tests -->
+                            <!-- Enable Spring virtual threads - the 
CamelVirtualThreadEnvironmentPostProcessor
+                                 will automatically set 
camel.threads.virtual.enabled=true -->
                             <systemPropertyVariables>
                                 
<spring.threads.virtual.enabled>true</spring.threads.virtual.enabled>
-                                
<camel.threads.virtual.enabled>true</camel.threads.virtual.enabled>
                             </systemPropertyVariables>
                         </configuration>
                     </plugin>
diff --git 
a/core/camel-spring-boot/src/main/java21/org/apache/camel/spring/boot/CamelVirtualThreadEnvironmentPostProcessor.java
 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelVirtualThreadEnvironmentPostProcessor.java
similarity index 84%
rename from 
core/camel-spring-boot/src/main/java21/org/apache/camel/spring/boot/CamelVirtualThreadEnvironmentPostProcessor.java
rename to 
core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelVirtualThreadEnvironmentPostProcessor.java
index ecac3587148..453583963ee 100644
--- 
a/core/camel-spring-boot/src/main/java21/org/apache/camel/spring/boot/CamelVirtualThreadEnvironmentPostProcessor.java
+++ 
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelVirtualThreadEnvironmentPostProcessor.java
@@ -34,15 +34,25 @@ public class CamelVirtualThreadEnvironmentPostProcessor 
implements EnvironmentPo
 
     private static final Logger LOG = 
LoggerFactory.getLogger(CamelVirtualThreadEnvironmentPostProcessor.class);
 
+    private static final int VIRTUAL_THREADS_MIN_JAVA_VERSION = 21;
+
     @Override
     public void postProcessEnvironment(ConfigurableEnvironment environment, 
SpringApplication application) {
         // Check if Spring Boot virtual threads are enabled
         String springVirtualThreads = 
environment.getProperty("spring.threads.virtual.enabled");
-        
+
         if ("true".equalsIgnoreCase(springVirtualThreads)) {
+            // Verify we're running on JDK 21+ where virtual threads are 
available
+            int javaVersion = Runtime.version().feature();
+            if (javaVersion < VIRTUAL_THREADS_MIN_JAVA_VERSION) {
+                LOG.debug("spring.threads.virtual.enabled=true but running on 
JDK {} (virtual threads require JDK 21+)",
+                        javaVersion);
+                return;
+            }
+
             // Set the Camel virtual threads system property early, before 
Camel classes are loaded
             String existingCamelProperty = 
System.getProperty("camel.threads.virtual.enabled");
-            
+
             if (existingCamelProperty == null) {
                 System.setProperty("camel.threads.virtual.enabled", "true");
                 LOG.info("Spring virtual threads enabled - automatically 
setting camel.threads.virtual.enabled=true");
diff --git 
a/core/camel-spring-boot/src/main/resources/META-INF/spring.factories 
b/core/camel-spring-boot/src/main/resources/META-INF/spring.factories
index fa7a54b8349..a0d9d865f47 100644
--- a/core/camel-spring-boot/src/main/resources/META-INF/spring.factories
+++ b/core/camel-spring-boot/src/main/resources/META-INF/spring.factories
@@ -14,3 +14,6 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
+
+org.springframework.boot.env.EnvironmentPostProcessor=\
+org.apache.camel.spring.boot.CamelVirtualThreadEnvironmentPostProcessor
diff --git 
a/core/camel-spring-boot/src/main/resources21/META-INF/spring.factories 
b/core/camel-spring-boot/src/main/resources21/META-INF/spring.factories
deleted file mode 100644
index e0a6e45de75..00000000000
--- a/core/camel-spring-boot/src/main/resources21/META-INF/spring.factories
+++ /dev/null
@@ -1,19 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-
-org.springframework.boot.env.EnvironmentPostProcessor=\
-org.apache.camel.spring.boot.CamelVirtualThreadEnvironmentPostProcessor
\ No newline at end of file
diff --git 
a/core/camel-spring-boot/src/test/java21/org/apache/camel/spring/boot/CamelVirtualThreadsTest.java
 
b/core/camel-spring-boot/src/test/java21/org/apache/camel/spring/boot/CamelVirtualThreadsTest.java
index e6bc4ec86ab..93da9a870ad 100644
--- 
a/core/camel-spring-boot/src/test/java21/org/apache/camel/spring/boot/CamelVirtualThreadsTest.java
+++ 
b/core/camel-spring-boot/src/test/java21/org/apache/camel/spring/boot/CamelVirtualThreadsTest.java
@@ -43,11 +43,6 @@ import static org.assertj.core.api.Assertions.assertThat;
                 properties = { "spring.threads.virtual.enabled=true" })
 public class CamelVirtualThreadsTest {
 
-    // Ensure camel.threads.virtual.enabled is set before any Camel classes 
are loaded
-    static {
-        System.setProperty("camel.threads.virtual.enabled", "true");
-    }
-
     @Autowired
     CamelContext context;
 
diff --git a/tests/camel-itest-spring-boot/pom.xml 
b/tests/camel-itest-spring-boot/pom.xml
index 3a443589494..8beb81e7429 100644
--- a/tests/camel-itest-spring-boot/pom.xml
+++ b/tests/camel-itest-spring-boot/pom.xml
@@ -233,4 +233,26 @@
         </plugins>
     </build>
 
+    <profiles>
+        <profile>
+            <id>skip-itest-github</id>
+            <activation>
+                <property>
+                    <name>ci.env.name</name>
+                    <value>github.com</value>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <skipTests>true</skipTests>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
 </project>

Reply via email to