<!--Define the MONGO object, corresponding to the Mongo,replica-set in the official MongoDB jar package, set the IP address and port of the cluster replica--> <mongo:mongo id= "MONGO" replica-set= "${mongo.hostport}" > <mongo:options connections-per-host= "${ Mongo.connectionsperhost} " threads-allowed-to-block-for-connection-multiplier=" ${ Mongo.threadsallowedtoblockforconnectionmultiplier} " connect-timeout=" ${mongo.connecttimeout} " max-wait-time= "${mongo.maxwaittime}" auto-connect-retry= " ${mongo.autoconnectretry} " socket-keep-alive=" ${mongo.socketkeepalive } " socket-timeout=" ${mongo.sockettimeout} " & nbsp slave-ok= "${mongo.slaveok}" write-number= "1" & nbsp write-timeout= "0" write-fsync= "True " /> </mongo:mongo> <!--MONGO Factory, through which to obtain MONGO instance, dbname for MongoDB database name, No words will be automatically created mongo-ref= "MONGO" and <mongo:mongo id= "MONGO" depend on - <mongo:db-factory Dbname= "Data" mongo-ref= "MONGO"/> <!--MongoDB's main operations object, All of the additions and deletions to MongoDB are performed through it --> <bean id= "mongotemplate" class= " Org.springframework.data.mongodb.core.MongoTemplate "> <constructor-arg name= "Mongodbfactory" ref= "Mongodbfactory"/> </bean> #Mongodb settingmongo.hostport=127.0.0.1:27017mongo.connectionsperhost= 8mongo.threadsallowedtoblockforconnectionmultiplier=4# Connection Timeout Time mongo.connecttimeout=1000# wait time mongo.maxwaittime= 1500mongo.autoconnectretry=truemongo.socketkeepalive=true#socket Timeout Time Mongo.sockettimeout=1500mongo.slaveok=true mysql (using Proxool connection pooling technology) Proxool is a Java database connection pooling technique. proxool-0.9.1.jarproxool-cglib-0.9.1.jar First step: Call the corresponding applicationcontext-proxool.xml in Web. XML, for example: in Web. XML (* For wildcard characters, you can query to Applicationcontext-proxool.xml) <context-param> <param-name> contextconfiglocation</param-name> <param-value>classpath*: applicationcontext*.xml</param-value> </context-param> Step Two: Write the connection pool in Applicationcontext-proxool.xml <bean id= "Datasourcetarget" class= " Org.logicalcobwebs.proxool.ProxoolDataSource "> <property name=" Driver "value=" ${ Jdbc.driverclassname} "/> <property name=" Driverurl "value=" ${jdbc.url} "></property> <property name= "user" value= "${jdbc.username}"/> <property name= "password" value= "${jdbc.password}"/ > <property name= "Alias" value= "Site_ds"/> <!--minimum number of idle connections--> <property Name= "Prototypecount" value= "${proxool.prototypecount} "/> <!--allow maximum number of connections, exceeding this connection, and then waiting in the queue when requested, the maximum number of waiting requests is determined by Simultaneousbuildthrottle--> < Property Name= "Maximumconnectioncount" value= "${proxool.maximumconnectioncount}"/> <!--minimum number of connections-- <property name= "Minimumconnectioncount" value= "${proxool.minimumconnectioncount}"/> <!-- The maximum time a thread holds a connection, regardless of whether the connection is in an active state, and automatically clears the connection if the thread is held for more than this time . but most of the time 5 minutes is not enough, so it needs to be set in the configuration file, The unit is in milliseconds (ms). --> <property name= "Maximumactivetime" value= "86400000"/> <!--refers to the maximum number of requests waiting in the queue because no idle connections can be allocated. user connections exceeding this number of requests will not be accepted--> <property name= "Simultaneousbuildthrottle" value= "/> <property" Name= "Housekeepingtestsql" value= "select Current_date"/></bean><!--
Spring officially recommends using Lazyconnectiondatasourceproxy
(http://static.springsource.org/spring/docs/2.5.6/api/org/springframework/jdbc/datasource/ lazyconnectiondatasourceproxy.html).
Purpose: 1). When the Hiberante hit cache is resolved, a SET autocommit=0,commit,set autocommit=0 operation problem is initiated against the database;
2). Resolve the performance impact of READ_ONLY transactions--
<!--personally think it's used to manage data sources--
<bean id= "DataSource"
class= "Org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" >
<property name= "Targetdatasource" >
<ref local= "Datasourcetarget"/>
</property>
</bean>
<bean id= "TransactionManager"
class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init= "true" >
<property name= "DataSource" ref= "DataSource"/>
</bean>
<bean id= "Namematch" class= "Org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource" >
<property name= "Properties" >
<props>
<prop key= "*" >PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean> <!--uses the principle of interceptors. --> <bean id= "Transactioninterceptor" class= " Org.springframework.transaction.interceptor.TransactionInterceptor "> <!-- The transaction interceptor Bean requires a dependency injection into a transaction manager--> <property name= "TransactionManager" > <ref bean= " TransactionManager "/> </property> <!--Transaction propagation properties--> <property name=" Transactionattributesource "> <ref bean=" Namematch "/> </property> </bean > <bean id= "Txproxy" class= " Org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator "> <property name=" Beannames " > <list> <value>*Manager</value> <value>*service </value> </list> </property> <property name= "Interceptornames" > <list> <value>transactionInterceptor</value> &NBsp;</list> </property> </bean> <!--1: Configure a JdbcTemplate instance and place this "shared", "secure" instance injected into different DAO classes go to--> <bean id= "JdbcTemplate" class= "Org.springframework.jdbc.core.JdbcTemplate" > <property name= "DataSource" ref= "DataSource"/> </bean> Step three: Due to the trouble of writing parameters in Applicationcontext-proxool.xml, write the parameters in Applicationcontext-database.properties as follows: #SQL DB setttingjdbc.driverclassname=com.mysql.jdbc.driverjdbc.url=jdbc\:mysql\://127.0.0.1\:3306/ Databasejdbc.username=rootjdbc.password=rootproxool.maximumconnectioncount=50proxool.minimumconnectioncount= 1proxool.prototypecount=1
MongoDB (Spring partial configuration)