<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                **1. 拆分Spring配置文件的目的** (1)項目規模大,配置文件的可讀性、維護性差。 (2)團隊開發,多人修改同一個配置文件,易發生沖突。 <br/> **2. 拆分策略有兩種** (1)公用配置 + 每個系統模塊單獨一個配置文件(DAO + Service + Web控制器),適用于多人開發的團隊。 :-: ![](https://img.kancloud.cn/1b/d1/1bd1478407e0fbfe0fb1cf0b94077d41_386x364.png) (2)公用配置 + DAO層的Bean配置 + Service層的Bean配置 + Web控制器層的Bean配置,適用于個人開發或少數人團隊開發。 :-: ![](https://img.kancloud.cn/b3/87/b3879d27c38a9ebe8593ce8dda204476_328x273.png) <br/> **3. 配置文件拆分演示** 下面演示第2種拆分策略,步驟如下: (1)將一些公共配置放在`ApplicationContext.xml`文件中,如數據源、事務管理等。 ```xml <?xml version="1.0" encoding="UTF-8"?> <beans ...> <!-- 配置數據源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/mybatis?useUnicode=true&amp;characterEncoding=UTF-8"/> <property name="username" value="root"/> <property name="password" value="admin"/> </bean> <!-- 創建sqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- 注入mapper.xml --> <property name="mapperLocations"> <list> <value>classpath:mapper/StudentMapper.xml</value> </list> </property> </bean> </beans> ``` (2)將dao層配置放在`ApplicationContext-dao.xml`文件中。 ```xml <?xml version="1.0" encoding="UTF-8"?> <beans ...> <!-- 創建dao層--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 該配置會將dao層下的所有xxxMapper接口注入到basePackage中 --> <property name="basePackage" value="dao"/> </bean> </beans> ``` (3)將service層的配置放在`ApplicationContext-service.xml`文件中。 ```xml <?xml version="1.0" encoding="UTF-8"?> <!-- default-autowire="byName"表示全局的Service采用按名字自動裝配 --> <beans default-autowire="byName" ...> <!-- 創建service層 --> <bean id="studentService" class="service.imp.StudentServiceImpl"> <!--<property name="studentMapper" ref="studentMapper"/>--> </bean> </beans> ``` (4)將拆分的Spring配置文件合并。 合并方式一:使用`ClassPathXmlApplicationContext(String... configLocations)`將多個配置文件合并。 ```java @org.junit.Test public void test() { ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml" ,"ApplicationContext-dao.xml", "ApplicationContext-service.xml"); StudentService studentService = (StudentService) context.getBean("studentService"); } ``` 合并方式二:`<import resource="xxx.xml"/>`在一個配置文件中導入其它配置。 *`ApplicationContext.xml`* ```xml <import resource="ApplicationContext-dao.xml"/> <import resource="ApplicationContext-service.xml"/> ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看