GaneshPatil7517 commented on code in PR #16005:
URL: https://github.com/apache/dubbo/pull/16005#discussion_r2696824225
##########
dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/SpringBoot3Condition.java:
##########
@@ -21,9 +21,44 @@
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
+/**
+ * Condition that matches when running on Spring Boot 3.x or higher.
+ *
+ * <p>This condition is used to enable Spring Boot 3.x specific
auto-configuration
+ * that requires Jakarta EE APIs (jakarta.servlet.*) instead of Java EE APIs
(javax.servlet.*).
+ *
+ * <p>Compatible with Spring Boot 3.5.x and Spring Cloud 2025.0.0.
+ *
+ * @since 3.2.0
+ */
public class SpringBoot3Condition implements Condition {
- public static boolean IS_SPRING_BOOT_3 =
SpringBootVersion.getVersion().charAt(0) >= '3';
+ /**
+ * Cached result indicating if we're running on Spring Boot 3.x or higher.
+ * Uses safe version parsing to handle edge cases.
+ */
+ public static final boolean IS_SPRING_BOOT_3 = isSpringBoot3OrHigher();
+
+ private static boolean isSpringBoot3OrHigher() {
Review Comment:
When SpringBootVersion#getVersion() returns null or empty, the
implementation falls back to checking for the presence of Jakarta Servlet API
(jakarta.servlet.Servlet):
if (version == null || version.isEmpty()) {
// Fallback: check for Jakarta Servlet API presence (Spring Boot 3
indicator)
try {
Class.forName("jakarta.servlet.Servlet");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
This is a reliable fallback because:
Spring Boot 3.x uses Jakarta EE 9+ (jakarta.* namespace)
Spring Boot 2.x uses Java EE 8 (javax.* namespace)
So if jakarta.servlet.Servlet is on the classpath → Spring Boot 3.x,
otherwise → Spring Boot 2.x or earlier.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]