GaneshPatil7517 commented on code in PR #16005:
URL: https://github.com/apache/dubbo/pull/16005#discussion_r2697066376
##########
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:
[SpringBootVersion.getVersion()](vscode-file://vscode-app/c:/Users/HP/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html)
reads the version from META-INF/MANIFEST.MF of the
[spring-boot](vscode-file://vscode-app/c:/Users/HP/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html)
JAR (specifically the Implementation-Version attribute). It can return null in
these scenarios:
Running from IDE without packaged JARs - During development when classes are
loaded from
[classes](vscode-file://vscode-app/c:/Users/HP/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html)
instead of JARs, no MANIFEST.MF exists
Spring Boot JAR is shaded/repackaged - When the JAR is processed by
maven-shade-plugin or similar tools that may not preserve manifest attributes
Custom classloader issues - In some application servers or modular
environments where the manifest cannot be located
That said, you raise a valid point - in normal production usage with
properly packaged Spring Boot applications,
[getVersion()](vscode-file://vscode-app/c:/Users/HP/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html)
should always return a valid version string.
If you think the fallback is unnecessary, I can simplify to:
String version = SpringBootVersion.getVersion();
return version != null && !version.isEmpty() && version.charAt(0) >= '3';
This still handles null safely but removes the Jakarta Servlet fallback.
Would this be acceptable?
--
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]