Connecting the database with the methods used in spring and MyBatis can not be the same, mybaits can not write the database configuration file
Spring's Connection method
<!--read the contents of the property file (. properties)--
<!--location: Specifies the position and file name of the property file to be read.
Note: classpath: Indicates that the contents of the property file are read by the path according to the classpath.
and store the content on the Properties object-
Log in data file for database
File name db.properties
#db connection Parametersdriver=oracle.jdbc.driver.OracleDriverurl=jdbc:oracle:thin:@ 176.217.20.254:1521: Tarenauser=abc1234pwd=abc1234#datasource parametersinitsize=1 maxsize=3
Write in the XML configuration file:
<util:properties id="DB"location="classpath:db.properties"/> <!--Configuring connection pooling--<bean id="DS" class="Org.apache.commons.dbcp.BasicDataSource"Destroy-method="Close"> <property name="Driverclassname"Value="#{db.driver}"/> <property name="URL"Value="#{db.url}"/> <property name="username"Value="#{db.user}"/> <property name="Password"Value="#{db.pwd}"/> <property name="InitialSize"Value="#{db.initsize}"/> </bean>
MyBatis Method of Connection
MyBatis directly in the XML write
1<environmentsdefault= "Environment" >2<environment id= "Environment" >3<transactionmanager type= "JDBC"/>//Select to use the JDBC interface4<datasource type= "Pooled" >5<property name= "Driver" value= "Oracle.jdbc.driver.OracleDriver"/>6<property name= "url"7Value= "Jdbc:oracle:thin:@176.217.20.254:1521:tarena"/>8<property name= "username" value= "abc1234"/>9<property name= "Password" value= "abc1234"/>Ten</dataSource> One</environment> A</environments>
September 3, 2017 different ways to connect databases in spring and MyBatis