Home > database >  Novice, could you tell me how to integrate SSM framework mongo, integrated mybatis should need mappe
Novice, could you tell me how to integrate SSM framework mongo, integrated mybatis should need mappe

Time:09-24

As title belongs to, I according to the online tutorial this would happen after integration, isn't me to integrate the wrong

CodePudding user response:

The first step to configure the maven. I currently used here is the latest

& lt; ! - directing a start - & gt;
& lt; Dependency>
& lt; GroupId> Org. Mongodb
& lt; ArtifactId> Mongo Java - driver
& lt; Version> 3.9.1 & lt;/version>
& lt;/dependency>
& lt; Dependency>
& lt; GroupId> Org. Springframework. Data
& lt; ArtifactId> Spring - data - mongodb
& lt; Version> 1.7.1. RELEASE
& lt;/dependency>
& lt; ! - directing end - & gt;
The second step is to create mongo. The properties, of which the
 


# DB name
Mongo. Dbname=erp_company
# username
Mongo. Username=HSJG
# password
Mongo. Password=1
# host
Mongo. Host=127.0.0.1
# port
Mongo. Port=27017
# xiancheng zui da zu se shu
Mongo. ConnectionsPerHost=8
# xiancheng dui lie shu
Mongo. ThreadsAllowedToBlockForConnectionMultiplier=4
# connectTimeout ms
Mongo. ConnectTimeout=1500
# maxWaitTime
Mongo. MaxWaitTime=1500
# autoConnect
Mongo. AutoConnectRetry=true
# socketKeepAlive
Mongo. SocketKeepAlive=true
# socketTimeout
Mongo. SocketTimeout=1500
# du xie fen li
Mongo. SlaveOk=true
The third step to create the spring - mongo. XML


& lt; ? The XML version="1.0" encoding="utf-8"?>
& lt; Beans XMLNS="http://www.springframework.org/schema/beans"
XMLNS: xsi="http://www.w3.org/2001/XMLSchema-instance" XMLNS: p="http://www.springframework.org/schema/p"
XMLNS: aop="http://www.springframework.org/schema/aop" XMLNS: context="http://www.springframework.org/schema/context"
XMLNS: tx="http://www.springframework.org/schema/tx" XMLNS: security="http://www.springframework.org/schema/security"
XMLNS: mongo="http://www.springframework.org/schema/data/mongo"
Xsi: schemaLocation="HTTP://http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd "& gt;


& lt; ! - loading mongo attribute configuration file - & gt;
& lt; Context: the property - placeholder location="classpath:/system/mongo. The properties of" ignore - unresolvable="true"/& gt;

& lt; ! - we use Mongo's version is 3. X, so in constructing this passage according to the Mongo class constructor, to construct the different version may cause the constructor - & gt;
& lt; Mongo: mongo - client id="mongo" host="${mongo. Host}" port="${mongo. Port}" & gt;
& lt; Mongo: client - options connections - per - host="${mongo. ConnectionsPerHost}"
Threads allowed - to - block - for - connection - multiplier="${mongo. ThreadsAllowedToBlockForConnectionMultiplier}"
Connect - timeout="${mongo. ConnectTimeout}" Max - wait - time="${mongo. MaxWaitTime}"
Socket -- keep alive="${mongo. SocketKeepAlive}" socket - timeout="${mongo. SocketTimeout}"/& gt;
& lt;/mongo: mongo - client>

& lt; ! - a user validation & gt;
& lt; Bean id="userCredentials" & gt;
& lt; The constructor - arg name="username" value="https://bbs.csdn.net/topics/${mongo. Username}"/& gt;
& lt; The constructor - arg name="password" value="https://bbs.csdn.net/topics/${mongo. Password}"/& gt;
& lt;/bean>
& lt; ! - mongo factory, through it to get mongo instance, dbname for directing a database name, if not automatically created - & gt;
& lt; Bean id="mongoDbFactory
">
& lt; The constructor - arg ref="mongo"/& gt;
& lt; The constructor - arg value="https://bbs.csdn.net/topics/${mongo. Dbname}"/& gt;
& lt;/bean>

& lt; Bean id="mappingContext
"/>

& lt; Bean id="defaultMongoTypeMapper
">
& lt; The constructor - arg name="typeKey & gt;"
& lt; Null/& gt;
& lt;/constructor - arg>
& lt;/bean>

& lt; ! - a collection of maps - & gt;
& lt; Bean id="mappingMongoConverter
">
& lt; The constructor - arg name="mongoDbFactory ref=" mongoDbFactory "/" & gt;
& lt; The constructor - arg name="mappingContext ref=" mappingContext "/" & gt;
& lt; The property name="typeMapper ref=" defaultMongoTypeMapper "/" & gt;
& lt;/bean>

& lt; ! All, for the main operand of the mongo, mongo's add and delete operation is done by it - & gt;
& lt; Bean id="mongoTemplate" & gt;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull