Browse Source

Retrieve MongoDB driver version reflectively.

To avoid inlining of the final/static version value, we're using reflection to look up the version value.

Closes #4937
pull/4942/head
Mark Paluch 8 months ago
parent
commit
6f11c08064
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 8
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/MongoClientVersion.java

8
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/MongoClientVersion.java

@ -15,9 +15,12 @@ @@ -15,9 +15,12 @@
*/
package org.springframework.data.mongodb.util;
import java.lang.reflect.Field;
import org.springframework.data.util.Version;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import com.mongodb.internal.build.MongoDriverVersion;
@ -96,8 +99,9 @@ public class MongoClientVersion { @@ -96,8 +99,9 @@ public class MongoClientVersion {
if (ClassUtils.isPresent("com.mongodb.internal.build.MongoDriverVersion", classLoader)) {
try {
return Version.parse(MongoDriverVersion.VERSION);
} catch (IllegalArgumentException exception) {
Field field = ReflectionUtils.findField(MongoDriverVersion.class, "VERSION");
return field != null ? Version.parse("" + field.get(null)) : null;
} catch (ReflectiveOperationException | IllegalArgumentException exception) {
// well not much we can do, right?
}
}

Loading…
Cancel
Save