欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)文章

  • JAVA反射機制中g(shù)etClass和class對比分析

    JAVA反射機制中g(shù)etClass和class對比分析

    這篇文章主要介紹了JAVA反射機制中g(shù)etClass和class對比分析,具有一定參考價值,需要的朋友可以了解下。
    2017-11-11
  • Spring使用Redis限制用戶登錄失敗的次數(shù)及暫時鎖定用戶登錄權(quán)限功能

    Spring使用Redis限制用戶登錄失敗的次數(shù)及暫時鎖定用戶登錄權(quán)限功能

    這篇文章主要介紹了Spring使用Redis限制用戶登錄失敗的次數(shù)及暫時鎖定用戶登錄權(quán)限功能,本文通過實例代碼給大家介紹的非常詳細,需要的朋友可以參考下
    2024-02-02
  • springboot項目快速搭建的方法步驟

    springboot項目快速搭建的方法步驟

    這篇文章主要介紹了springboot項目快速搭建的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-12-12
  • 深入解析反編譯字節(jié)碼文件中的代碼邏輯JVM中的String操作

    深入解析反編譯字節(jié)碼文件中的代碼邏輯JVM中的String操作

    這篇文章主要介紹了深入解析反編譯字節(jié)碼文件中的代碼邏輯JVM中的String操作,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-10-10
  • 在Java中FreeMarker?模板來定義字符串模板

    在Java中FreeMarker?模板來定義字符串模板

    這篇文章主要介紹了在Java中FreeMarker?模板來定義字符串模板,文章基于Java的相關(guān)資料展開詳細內(nèi)容,需要的小伙伴可以參考一下
    2022-04-04
  • 深入剖析Java ArrayQueue(JDK)的源碼

    深入剖析Java ArrayQueue(JDK)的源碼

    本篇文章主要給大家介紹一個比較簡單的JDK為我們提供的容器ArrayQueue,這個容器主要是用數(shù)組實現(xiàn)的一個單向隊列,整體的結(jié)構(gòu)相對其他容器來說就比較簡單了,感興趣的可以了解一下
    2022-08-08
  • 重寫equals的同時為何要重寫hashCode?

    重寫equals的同時為何要重寫hashCode?

    這篇文章主要給大家介紹了關(guān)于重寫equals的同時為何要重寫hashCode的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-01-01
  • Spring中filter過濾器的定義方法

    Spring中filter過濾器的定義方法

    這篇文章主要介紹了Spring中filter過濾器的定義方法,Filter 程序是一個實現(xiàn)了特殊接口的 Java 類,與 Servlet 類似,也是由 Servlet 容器進行調(diào)用和執(zhí)行的,需要的朋友可以參考下
    2023-08-08
  • Compare And Swap底層原理及代碼示例詳解

    Compare And Swap底層原理及代碼示例詳解

    這篇文章主要介紹了Compare And Swap底層原理及代碼示例詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-10-10
  • Spring 項目常用pom文件的依賴

    Spring 項目常用pom文件的依賴

    這篇文章主要介紹了Spring 項目常用pom文件的依賴,文中給大家提到了Spring boot starter pom的依賴關(guān)系說明,需要的朋友參考下吧
    2018-03-03

最新評論