@@ -36,6 +36,22 @@ public class DatabaseClientPropertySource {
36
36
37
37
static {
38
38
connectionPropertyHandlers = new LinkedHashMap <>();
39
+
40
+ // Connection string is handled first so that certain properties can override it as needed. This is useful
41
+ // for e.g. specifying a specific host in a cluster while reusing the rest of the connection string.
42
+ connectionPropertyHandlers .put (PREFIX + "connectionString" , (bean , value ) -> {
43
+ if (value instanceof String ) {
44
+ ConnectionString cs = new ConnectionString ((String ) value , "connection string" );
45
+ bean .setHost (cs .getHost ());
46
+ bean .setPort (cs .getPort ());
47
+ if (cs .getDatabase () != null && cs .getDatabase ().trim ().length () > 0 ) {
48
+ bean .setDatabase (cs .getDatabase ());
49
+ }
50
+ } else {
51
+ throw new IllegalArgumentException ("Connection string must be of type String" );
52
+ }
53
+ });
54
+
39
55
connectionPropertyHandlers .put (PREFIX + "host" , (bean , value ) -> {
40
56
if (value instanceof String ) {
41
57
bean .setHost ((String ) value );
@@ -59,18 +75,6 @@ public class DatabaseClientPropertySource {
59
75
throw new IllegalArgumentException ("Database must be of type String" );
60
76
}
61
77
});
62
- connectionPropertyHandlers .put (PREFIX + "connectionString" , (bean , value ) -> {
63
- if (value instanceof String ) {
64
- ConnectionString cs = new ConnectionString ((String ) value , "connection string" );
65
- bean .setHost (cs .getHost ());
66
- bean .setPort (cs .getPort ());
67
- if (cs .getDatabase () != null && cs .getDatabase ().trim ().length () > 0 ) {
68
- bean .setDatabase (cs .getDatabase ());
69
- }
70
- } else {
71
- throw new IllegalArgumentException ("Connection string must be of type String" );
72
- }
73
- });
74
78
connectionPropertyHandlers .put (PREFIX + "basePath" , (bean , value ) -> {
75
79
if (value instanceof String ) {
76
80
bean .setBasePath ((String ) value );
0 commit comments