Description of the properties node in the configuration file of mybatis_review

Source: Internet
Author: User
Properties settings

The configuration in the Mybatis-config.xml file used in the demo project is as follows:

<span style="font-family:KaiTi_GB2312;"><?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration>  <properties resource="com/samsung/mybatis/jdbc.properties">    <property name="username" value="chenzw"/>    <property name="password" value="1258577"/>  </properties>  <settings>    <setting name="logImpl" value="LOG4J"/>  </settings>  <environments default="development">    <environment id="development">      <transactionManager type="JDBC"/>      <dataSource type="POOLED">        <property name="driver" value="${driver}"/>        <property name="url" value="${url}"/>        <property name="username" value="${username}"/>        <property name="password" value="${password}"/>      </dataSource>    </environment>  </environments>  <mappers>    <mapper resource="com/samsung/mybatis/tiger.xml"/>  </mappers></configuration></span>


The content in JDBC. properties referenced in the preceding configuration file is as follows:

<span style="font-family:KaiTi_GB2312;">driver=com.mysql.jdbc.Driverurl=jdbc:mysql://127.0.0.1:3306/testusername=chenzwpassword=7758521</span>

Loading Sequence of Properties

The order in which mybatis loads properties is as follows:

1) First, mybatis will find the properties content in the configuration file, for example, username = chenzw above and Password = 1258577 above, in parsing XML files, the relevant objects are recorded in properties in the configuration file.

2) then, mybatis will find the content pointed to by the properties node property resource. For example, in the demo above, the content pointed to by this property is JDBC. in the properties file, mybatis will parse the above content and get the content of the properties file. At this time, we will find that there is a password conflict, there are two different values of the Password attribute, here, remember that mybatis will change the password file to 7758521 Based on the found information.

3) In fact, all the parameters configured here will be passed to the relevant method for execution using the property value of a record. The called method is described as follows in the mybatis API documentation:

Sqlsessionfactoryfactory = sqlsessionfactorybuilder. Build (reader, props );

Sqlsessionfactoryfactory = sqlsessionfactorybuilder. Build (reader, environment, props );

Therefore, if a change occurs in the parameter, it is equal to the result of the test. The last step is replaced by someone else, and the previous steps have become useless.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.