2016-02-09 27 views
1

對於基於彈簧的項目,我使用mongoTemplate來查詢mongo DB。 爲此,我使用了systemProperties來配置mongo選項。使用彈簧創建的mongoclient的LOG/print mongo選項

現在我想在我的服務器的LOG中打印這些mongo選項的值,但無法找到合適的方法來執行此操作。請建議。以下是我的spring 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 /> 

回答

0

解決它。 我們可以通過在mongoTemplate bean上調用以下函數來打印它:

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