使用spring创建的mongoclient的LOG /打印mongo选项

时间:2016-02-09 06:50:51

标签: spring mongodb

对于基于spring的项目,我使用mongoTemplate来查询mongo DB。 为此,我使用了systemProperties来配置mongo选项。

现在我想在服务器的LOG中打印这些mongo选项的值,但无法找到合适的方法来执行此操作。请建议。以下是我的春天mongo xml。

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task" xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd">



<!-- Mongo Template for Test -->
<mongo:mongo replica-set="#{systemProperties['mongoTest.replicaset']}" id="mongoCocofs">
    <mongo:options auto-connect-retry="true" connections-per-host="#{systemProperties['mongoTest.connPerHost']?:'80'}" threads-allowed-to-block-for-connection-multiplier="#{systemProperties['mongoTest.threadAllowedForConnMultiplier']?:'5'}" slave-ok="true"/>
</mongo:mongo>

<mongo:db-factory dbname="test" mongo-ref="mongoTest" id="mongoDbFactoryTest" />

<bean id="mongoTemplateTest" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg name="mongoDbFactory" ref="mongoDbFactoryCocofs" />
</bean>

<context:annotation-config />

1 个答案:

答案 0 :(得分:0)

解决了它。 我们可以通过在mongoTemplate bean上调用以下函数来打印它:

mongoTemplate.getDb().getMongo().getMongoOptions()