MongoDB去除_class属性
连接MongoDB数据库属性文件
mongo.host=Mongodb连接地址
mongo.port=27017
mongo.poolSize=50
mongo.user=
mongo.password=
mongo.database=Mongodb数据库名字
spring配置文件如下:
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
http://www.springframework.org/schema/data/mongohttp://www.springframework.org/schema/data/mongo/spring-mongo-1.1.xsd
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<propertyname="locations">
<list>
<value>classpath:META-INF/conf/config.properties</value>
<value>classpath:META-INF/conf/jdbc.properties</value>
<value>classpath:META-INF/conf/dubbo.properties</value>
</list>
</property>
</bean>
<!--MongoDB连接配置-->
<mongo:mongohost="${mongo.host}"port="${mongo.port}"/>
<mongo:db-factorydbname="${mongo.database}"mongo-ref="mongo"/>
<beanid="mappingContext"class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
<beanid="mappingMongoConverter"class="org.springframework.data.mongodb.core.convert.MappingMongoConverter">
<constructor-argname="mongoDbFactory"ref="mongoDbFactory"/>
<constructor-argname="mappingContext"ref="mappingContext"/>
<propertyname="typeMapper"ref="defaultMongoTypeMapper"/>
</bean>
<beanid="defaultMongoTypeMapper"class="org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper">
<!--这里用来删除MongoDB中的_class属性,设置为空-->
<constructor-argname="typeKey">
<null/>
</constructor-arg>
</bean>
<beanid="mongoTemplate"class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-argname="mongoDbFactory"ref="mongoDbFactory"/>
<constructor-argname="mongoConverter"ref="mappingMongoConverter"/>
</bean>
</beans>
以上是放在spring配置文件中的,须引入spring-data-mongodb、
mongo-java-driver的JAR包