<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                實例化一個容器是簡單而直接的。可以通過將一個或多個資源字符串(可以是本地文件系統中,或者是 Java類路徑下的配置文件路徑)提供給`ApplicationContext`的構造器,這樣容器就可以從多個外部資源中加載配置元數據。 ~~~ //從類路徑下加載多個配置文件來創建容器 ApplicationContext context = new ClassPathXmlApplicationContext("services.xml", "daos.xml"); ~~~ > 當你學習了 Spring IOC 容器后,你可能想了解更多與資源抽象有關的信息,該內容在[2.資源](2.資源.md)章節中講解。它提供了一種方便的機制從URL 語法中定義的位置來讀取輸入流。特別地,在[2.7.應用上下文和資源路徑](2.7.應用上下文和資源路徑.md)章節中會講到:資源路徑被用來構建應用上下文。 下面是服務層對象(`services.xml`)的配置文件。 ~~~ <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- 服務列表 --> <bean id="petStore" class="org.springframework.samples.jpetstore.services.PetStoreServiceImpl"> <property name="accountDao" ref="accountDao"/> <property name="itemDao" ref="itemDao"/> <!-- 這里編寫此Bean所依賴的其他 Bean的配置 --> </bean> <!-- 這里還有更多服務相關 Bean 的定義 --> </beans> ~~~ 下面是數據訪問層對象( `daos.xml`)的配置文件。 ~~~ <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="accountDao" class="org.springframework.samples.jpetstore.dao.jpa.JpaAccountDao"> <!-- 這里編寫此Bean所依賴的其他 Bean的配置 --> </bean> <bean id="itemDao" class="org.springframework.samples.jpetstore.dao.jpa.JpaItemDao"> <!-- 這里編寫此Bean所依賴的其他 Bean的配置 --> </bean> <!-- 這里還有更多數據訪問相關 Bean 的定義--> </beans> ~~~ 在前面的樣例中,服務層對象由`PetStoreServiceImpl`以及兩個數據訪問層對象:`JpaAccountDao`,`JpaItemDao`(基于 JPA 對象關系映射規范)組成。`name`表示Bean的屬性,`ref`表示對其它 Bean的引用。`id`和`ref`表示了對象間的依賴關系(`id`屬性所在 Bean 的定義為被引用方,而另一方則為引用方)。對象依賴的詳細配置請參見[1.4.依賴](1.4.依賴.md)。 * * * * * ### **組合基于 XML 的配置元數據文件** 分隔Bean 的定義到多個配置文件是有意義的,在應用的架構中,每一個獨立的XML 配置表示一個邏輯層或者模塊。 &emsp; 你可以通過給`ApplicationContext`的構造器中傳入多個資源路徑,以此來從多個地方加載配置文件,就像上一小節展示的那樣。此外,你也可以通過`<import>`標簽從其他文件中加載 Bean 的定義,比如: ~~~ <beans> <import resource="services.xml"/> <import resource="resources/messageSource.xml"/> <import resource="/resources/themeSource.xml"/> <bean id="bean1" class="..."/> <bean id="bean2" class="..."/> </beans> ~~~ 在上面的例子中加載了三個外部Bean 的定義文件:`services.xml`、`messageSource.xml`、`themeSource.xml`。因為都是導入的相對路徑,所以`services.xml`必須和導入文件(總的配置文件)處于同一目錄或者類路徑下。而`messageSource.xml`和`themeSource.xml`必須在導入文件所在目錄的resource目錄下。正如你所看到的,路徑前面的斜線都被忽略了,考慮到給定的路徑都是相對的,所以最好都不加斜線。所有被導入的文件都處于頂級標簽`<bean/>`之下,必須遵循 Spring 定義的 XML 規范。 &emsp; > 雖然可以通過"../"來引用父路徑的文件,但是不推薦這么做。因為這樣會創建一個當前應用之外的依賴文件。特別地,被引用的文件也不推薦用"classpath:"URLs(例如:"classpath:../services.xml"),在運行時會選擇"最近的"根類路徑并跳轉到它的父目錄,當類路徑配置變化時會導致選擇了錯誤的目錄。 > >你可以一直使用全限定資源路徑來代替相對路徑,如比,你可以使用諸如"file:C:/config/services.xml"或者 "classpath:/config/services.xml"。但是,要知道這會和應用的配置和特定的絕對路徑耦合。更好的方式是間接使用絕對路徑,比如:使用"${}"占位符來表示絕對路徑,它會在 JVM 運行時被系統屬性識別。 > Bean 的命名空間提供了導入指令,更多的配置特性可以通過 Spring 提供的命名空間來獲取,比如"context"和"util"等命名空間。
                  <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>

                              哎呀哎呀视频在线观看