最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring配置文件的拆分和整合過程分析

 更新時間:2022年10月06日 10:45:25   作者:姓蔡小朋友  
在實際應用里,隨著應用規(guī)模的增加,系統(tǒng)中 Bean 數(shù)量也大量增加,導致配置文件非常龐大。為了避免這種情況的產(chǎn)生,提高配置文件的可讀性與可維護性,可以將Spring 配置文件分解成多個配置文件,感興趣的朋友跟隨小編一起看看吧

一、Spring配置文件拆分:

  • 在實際應用里,隨著應用規(guī)模的增加,系統(tǒng)中 Bean 數(shù)量也大量增加,導致配置文件非常龐大。為了避免這種情況的產(chǎn)生,提高配置文件的可讀性與可維護性,可以將Spring 配置文件分解成多個配置文件。
  • 拆分前:所有配置信息都在同一個配置文件中。

請?zhí)砑訄D片描述

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    <!--添加包掃描,通過掃描包內(nèi)的注解創(chuàng)建對象-->
    <context:component-scan base-package="org.example.controller"></context:component-scan>
    <context:component-scan base-package="org.example.service"></context:component-scan>
    <context:component-scan base-package="org.example.dao"></context:component-scan>
</beans>

按層拆分:不同層分別創(chuàng)建配置文件。

請?zhí)砑訄D片描述

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    <!--添加包掃描,通過掃描包內(nèi)的注解創(chuàng)建對象-->
    <context:component-scan base-package="org.example.controller"></context:component-scan>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    <!--添加包掃描,通過掃描包內(nèi)的注解創(chuàng)建對象-->
    <context:component-scan base-package="org.example.dao"></context:component-scan>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    <!--添加包掃描,通過掃描包內(nèi)的注解創(chuàng)建對象-->
    <context:component-scan base-package="org.example.service"></context:component-scan>
</beans>

二、Spring配置文件整合:

在我們解析Spring配置文件時每個ApplicationContext對象只能解析一個配置文件,所以我們需要把拆分后的所有配置文件整合后進行統(tǒng)一解析。

請?zhí)砑訄D片描述

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!--導入配置文件-->
    <!--單個導入-->
    <import resource="applicationContext_controller.xml"></import>
    <import resource="applicationContext_service.xml"></import>
    <import resource="applicationContext_dao.xml"></import>
    <!--批量導入-->
    <!--
      可以使用通配符進行整合。但此時要求父配置文件名不能滿足所能匹配的格式,否則將出現(xiàn)循環(huán)遞歸包含。
      就本例而言,父配置文件不能匹配 applicationContext-*.xml 的格式,即不能起名為applicationContext-total.xml。
    -->
    <import resource="applicationContext_*.xml"></import>
</beans>

到此這篇關(guān)于Spring配置文件的拆分和整合的文章就介紹到這了,更多相關(guān)Spring配置文件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

松阳县| 丹凤县| 阿勒泰市| 濮阳市| 阳新县| 旌德县| 茶陵县| 陆川县| 泾川县| 邻水| 宁德市| 枣阳市| 手游| 临潭县| 特克斯县| 农安县| 都兰县| 中宁县| 衡水市| 汪清县| 会昌县| 镇赉县| 金塔县| 杭锦旗| 都兰县| 增城市| 商南县| 霍林郭勒市| 溆浦县| 青龙| 桑日县| 玉门市| 巢湖市| 通道| 尼木县| 张家口市| 蒙山县| 张家港市| 阜康市| 福州市| 衡阳县|