Skip to content

Commit ea3fd92

Browse files
committed
Add compatibility for MongoConnectionDetails.getSslBundle method
Add reflective check for the getSslBundle method in MongoConnectionDetails interface to ensure compatibility between Spring Boot 3.4.x and 3.5.x. The method exists in Spring Boot 3.5 but not in 3.4, and our code needs to work with both versions. The implementation uses ReflectionUtils to check for the method's existence at runtime and invokes it only when available (Spring Boot 3.5+), falling back to returning null when using Spring Boot 3.4. Signed-off-by: Soby Chacko <[email protected]>
1 parent 15a5069 commit ea3fd92

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

spring-ai-spring-boot-testcontainers/src/main/java/org/springframework/ai/testcontainers/service/connection/mongo/MongoDbAtlasLocalContainerConnectionDetailsFactory.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,12 +16,16 @@
1616

1717
package org.springframework.ai.testcontainers.service.connection.mongo;
1818

19+
import java.lang.reflect.Method;
20+
1921
import com.mongodb.ConnectionString;
2022
import org.testcontainers.mongodb.MongoDBAtlasLocalContainer;
2123

2224
import org.springframework.boot.autoconfigure.mongo.MongoConnectionDetails;
25+
import org.springframework.boot.ssl.SslBundle;
2326
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionDetailsFactory;
2427
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionSource;
28+
import org.springframework.util.ReflectionUtils;
2529

2630
/**
2731
* A {@link ContainerConnectionDetailsFactory} implementation that provides
@@ -36,6 +40,7 @@
3640
* testcontainers in Spring Boot applications.
3741
*
3842
* @author Eddú Meléndez
43+
* @author Soby Chacko
3944
* @since 1.0.0
4045
* @see ContainerConnectionDetailsFactory
4146
* @see MongoConnectionDetails
@@ -44,6 +49,12 @@
4449
class MongoDbAtlasLocalContainerConnectionDetailsFactory
4550
extends ContainerConnectionDetailsFactory<MongoDBAtlasLocalContainer, MongoConnectionDetails> {
4651

52+
private static final Method GET_SSL_BUNDLE_METHOD;
53+
54+
static {
55+
GET_SSL_BUNDLE_METHOD = ReflectionUtils.findMethod(MongoConnectionDetails.class, "getSslBundle");
56+
}
57+
4758
@Override
4859
protected MongoConnectionDetails getContainerConnectionDetails(
4960
ContainerConnectionSource<MongoDBAtlasLocalContainer> source) {
@@ -66,6 +77,14 @@ public ConnectionString getConnectionString() {
6677
return new ConnectionString(getContainer().getConnectionString());
6778
}
6879

80+
// Conditional implementation based on whether the method exists
81+
public SslBundle getSslBundle() {
82+
if (GET_SSL_BUNDLE_METHOD != null) { // Boot 3.5.x+
83+
return (SslBundle) ReflectionUtils.invokeMethod(GET_SSL_BUNDLE_METHOD, this);
84+
}
85+
return null; // Boot 3.4.x (No-Op)
86+
}
87+
6988
}
7089

7190
}

0 commit comments

Comments
 (0)