Skip to content

Commit e0bc1e0

Browse files
mp911dechristophstrobl
authored andcommitted
DATAMONGO-1490 - Change the XML data type of boolean flags to String.
We now accept String data types for boolean flags in XML configurations. Boolean data types in the XSD don't allows use of property placeholders even if the resolved value could be converted to boolean. Affected fields by this change are: * `<mongo:repositories create-query-indexes=… />` * `<mongo:options ssl=…/>` * `<mongo:client-options ssl=… />` Original Pull Request: #389
1 parent fcb436d commit e0bc1e0

File tree

6 files changed

+32
-9
lines changed

6 files changed

+32
-9
lines changed

spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-1.8.xsd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ The MongoClientURI string.]]></xsd:documentation>
137137
</xsd:documentation>
138138
</xsd:annotation>
139139
</xsd:attribute>
140-
<xsd:attribute name="create-query-indexes" type="xsd:boolean" default="false">
140+
<xsd:attribute name="create-query-indexes" type="xsd:string" default="false">
141141
<xsd:annotation>
142142
<xsd:documentation>
143143
Enables creation of indexes for queries that get derived from the method name
@@ -541,7 +541,7 @@ This controls if the driver is allowed to read from secondaries or slaves. Defa
541541
]]></xsd:documentation>
542542
</xsd:annotation>
543543
</xsd:attribute>
544-
<xsd:attribute name="ssl" type="xsd:boolean">
544+
<xsd:attribute name="ssl" type="xsd:string">
545545
<xsd:annotation>
546546
<xsd:documentation><![CDATA[
547547
This controls if the driver should us an SSL connection. Defaults to false.
@@ -739,7 +739,7 @@ The socket timeout for connections used for the cluster heartbeat.
739739
]]></xsd:documentation>
740740
</xsd:annotation>
741741
</xsd:attribute>
742-
<xsd:attribute name="ssl" type="xsd:boolean">
742+
<xsd:attribute name="ssl" type="xsd:string">
743743
<xsd:annotation>
744744
<xsd:documentation><![CDATA[
745745
This controls if the driver should us an SSL connection. Defaults to false.

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/MongoNamespaceTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.context.ApplicationContext;
3030
import org.springframework.data.authentication.UserCredentials;
3131
import org.springframework.data.mongodb.MongoDbFactory;
32+
import org.springframework.data.mongodb.core.MongoClientFactoryBean;
3233
import org.springframework.data.mongodb.core.MongoFactoryBean;
3334
import org.springframework.data.mongodb.core.MongoOperations;
3435
import org.springframework.data.mongodb.core.ReflectiveMongoOptionsInvokerTestUtil;
@@ -38,6 +39,7 @@
3839
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3940

4041
import com.mongodb.Mongo;
42+
import com.mongodb.MongoClientOptions;
4143
import com.mongodb.MongoOptions;
4244
import com.mongodb.WriteConcern;
4345

@@ -101,6 +103,19 @@ public void testMongoSingletonWithSslEnabled() throws Exception {
101103
assertTrue("socketFactory should be a SSLSocketFactory", options.getSocketFactory() instanceof SSLSocketFactory);
102104
}
103105

106+
/**
107+
* @see DATAMONGO-1490
108+
*/
109+
@Test
110+
public void testMongoClientSingletonWithSslEnabled() {
111+
112+
assertTrue(ctx.containsBean("mongoClientSsl"));
113+
MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoClientSsl");
114+
115+
MongoClientOptions options = (MongoClientOptions) getField(mfb, "mongoClientOptions");
116+
assertTrue("socketFactory should be a SSLSocketFactory", options.getSocketFactory() instanceof SSLSocketFactory);
117+
}
118+
104119
/**
105120
* @see DATAMONGO-764
106121
*/

spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/config/MongoNamespaceTests-context.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929

3030
<mongo:db-factory dbname="database" mongo-ref="mongo"/>
3131

32+
<mongo:mongo-client id="mongoClientSsl">
33+
<mongo:client-options ssl="${mongoSsl.ssl}" />
34+
</mongo:mongo-client>
3235

33-
3436
<mongo:db-factory id="secondMongoDbFactory"
3537
host="localhost"
3638
port="27017"
@@ -49,7 +51,7 @@
4951
<mongo:mongo id="defaultMongo" host="localhost" port="27017"/>
5052

5153
<mongo:mongo id="mongoSsl" host="localhost" port="27017">
52-
<mongo:options ssl="true"/>
54+
<mongo:options ssl="${mongoSsl.ssl}"/>
5355
</mongo:mongo>
5456

5557
<mongo:mongo id="mongoSslWithCustomSslFactory" host="localhost" port="27017">

spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/config/mongo.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ mongo.socketKeepAlive=true
1010
mongo.fsync=true
1111
mongo.slaveOk=true
1212

13+
mongoSsl.ssl=true
14+

spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/RepositoryIndexCreationIntegrationTests-context.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xmlns:util="http://www.springframework.org/schema/util"
5+
xmlns:context="http://www.springframework.org/schema/context"
66
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
77
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
8-
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
8+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
99

10-
<mongo:db-factory dbname="repositories"/>
10+
<context:property-placeholder
11+
location="classpath:/org/springframework/data/mongodb/repository/mongo.properties"/>
12+
13+
<mongo:db-factory dbname="repositories"/>
1114
<mongo:mapping-converter base-package="org.springframework.data.mongodb.repository"/>
1215

1316
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
1417
<constructor-arg ref="mongoDbFactory"/>
1518
<constructor-arg ref="mappingConverter"/>
1619
</bean>
1720

18-
<mongo:repositories base-package="org.springframework.data.mongodb.repository" create-query-indexes="true" />
21+
<mongo:repositories base-package="org.springframework.data.mongodb.repository" create-query-indexes="${mongo.create-query-indexes}" />
1922

2023
</beans>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mongo.create-query-indexes=true

0 commit comments

Comments
 (0)