zoukankan      html  css  js  c++  java
  • mongodbtemplate配置

    <?xml version="1.0" encoding="UTF-8"?>
    <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:mongo="http://www.springframework.org/schema/data/mongo"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
    
        <mongo:mongo-client id="mongo" host="127.0.0.1" port="27017" credentials="user:pass@test">
            <mongo:client-options write-concern="NORMAL" />
        </mongo:mongo-client>
    
         <mongo:db-factory id="mongoDbFactory" dbname="test" mongo-ref="mongo"/>
        
    <!-- 添加这部分可以入库时屏蔽掉_class字段-->
        <bean id="mappingContext" class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" />

        <bean id="defaultMongoTypeMapper" class="org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper">
        <constructor-arg name="typeKey">
        <null />
        </constructor-arg>
        </bean>

        <bean id="mappingMongoConverter" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter">
        <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
        <constructor-arg name="mappingContext" ref="mappingContext" />
        <property name="typeMapper" ref="defaultMongoTypeMapper" />
        </bean>

         <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
            <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
        <constructor-arg name="mongoConverter" ref="mappingMongoConverter" /> </bean> </beans>

    将此文件包含进xml中。

    <import resource="classpath*:${mongoFileName}.xml"/>

  • 相关阅读:
    中文版CorelDRAW X8实战视频教程
    21天学通Java6(第5版)
    SAS高级统计分析教程(第2版)
    Access2007开发指南(修订版)
    Visual C++开发入行真功夫
    21天学编程系列:21天学通Java(第4版)
    102. Binary Tree Level Order Traversal
    78. Subsets
    79. Word Search
    46. Permutations
  • 原文地址:https://www.cnblogs.com/guochunyi/p/5259106.html
Copyright © 2011-2022 走看看