spring整合mongodb学习1:配置

spring 整合mongo
POM文件引入jar

<dependency>
	 <groupId>org.mongodb</groupId>
	 <artifactId>mongo-java-driver</artifactId>
	 <version>3.11.2</version>
 </dependency>
<dependency>
	 <groupId>org.springframework.data</groupId>
	 <artifactId>spring-data-mongodb</artifactId>
	 <version>2.2.1.RELEASE</version>
</dependency>

基础配置applicationContext.xml,mongo相关的配置:

<!-- mongodb连接池配置 -->
<mongo:mongo-client id="mongoClient" host="127.0.0.1" port="27017">
    <mongo:client-options
            write-concern="ACKNOWLEDGED"
            threads-allowed-to-block-for-connection-multiplier="5"
            max-wait-time="1200"
            connect-timeout="1000"/>
</mongo:mongo-client>

<!-- mongodb数据库工厂配置 -->
<mongo:db-factory dbname="znj" mongo-ref="mongoClient" />


<!-- mongodb模板配置 -->
<bean id="anotherMongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
	<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
</bean>

<!-- mongodb事物配置 -->
<bean id="transactionManager" class="org.springframework.data.mongodb.MongoTransactionManager">
	<property name="dbFactory" ref="mongoDbFactory"/>
</bean>

以上是相关配置

你可能感兴趣的:(mongodb学习,spring,mongodb,java)