[AIX Solaris HP-UX Linux Windows][z/OS]

在 SCA 應用程式中使用 Spring 2.5.5 儲存器 (已淘汰)

您可以使用「服務元件架構 (SCA)」程式設計模型,在 Spring 2.5.5 儲存器中呼叫遵循 Java™ 2 Platform Standard Edition (J2SE) 程式設計模型的 Bean。 產品支援使用 Spring Framework 所實作的元件,這些元件在複合定義中使用 <implementation.spring>

已淘汰的特性: 8.5.5.19 或更新版本 「服務元件架構 (SCA)」程式設計模型及範例已淘汰,並將在未來版本中移除。 您無法部署新的 SCA 商業層次應用程式。 如果您想要繼續使用 SCA 作為長期策略的一部分,請考量在 IBM Business Process Manager上管理應用程式。

開始之前

在開始這個主題中的程序之前,請執行下列動作:

  1. 熟悉 SCA Spring 元件實作 1.0.0 規格及 Spring 2.5.5 程式設計。 您必須使用 Spring 2.5.5 來實作 SCA 組合元件。 產品不支援其他層次的 Spring。

    產品只支援使用 J2SE 程式設計模型的 Spring Framework。 不支援本端 Java 命名和目錄介面 (JNDI) 查閱,因此產品不支援使用 Java Platform, Enterprise Edition (Java EE) 5 程式設計模型的 Spring Framework。 Spring 儲存器執行本端 JNDI 查閱的任何嘗試都會失敗。

  2. 決定將 implementation.springimplementation.jee 用於 Spring 應用程式。

    本主題中的程序討論在 SCA 元件實作中使用 implementation.spring 。 如果 Spring 應用程式實際上是特殊化 Java EE 應用程式,而不是使用 implementation.spring,您可以使用 implementation.jee 來定義 SCA 元件實作,並讓 Spring 應用程式成為 SCA 元件的一部分。

    例如,如果 Spring 應用程式包裝在 Web 模組 (WAR) 中,則您可以使用包含 WAR 檔的企業保存檔 (EAR) 作為使用 implementation.jee的元件實作。 Spring 應用程式的運作方式與之前一樣,且 Java EE 環境定義不受影響。 在 SCA 網域中無法使用 Spring Bean; 不過, EAR 檔內與 implementation.jee 相容的其他模組可以參與 SCA。

    如需使用 implementation.jee來部署 Spring 應用程式的相關資訊,請參閱使用現有 Java EE 模組和元件作為 SCA 實作的主題。

  3. 如果您決定使用 implementation.spring ,且您想要 Spring 應用程式中的 Bean 執行 JNDI 查閱,請設定 com.ibm.websphere.naming.WsnInitialContextFactory 作為 Bean 的內容。

    您可以搭配 implementation.spring在 Spring Bean 定義中使用廣域定義的 JNDI 資源,例如資料庫和 Connection Factory。 不過,您必須將已配置成參照 WebSphere 起始環境定義 Factory com.ibm.websphere.naming.WsnInitialContextFactory的 Spring JNDI 範本 Bean 設為執行 JNDI 查閱的 Bean 內容。 例如,下列 Bean 定義指定 myJndiResource Bean 使用 WebSphere 起始環境定義 Factory:

    <bean id="myJndiResource" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName" value="jdbc/myJndiResource"/>
      <property name="lookupOnStartup" value="true"/>
      <property name="cache" value="true"/>
      <property name="jndiTemplate" ref="wasJndiTemplate"/>
    </bean>
    
    <bean id="wasJndiTemplate" class="org.springframework.jndi.JndiTemplate">
      <property name="environment">
        <props>
          <prop key="java.naming.factory.initial">com.ibm.websphere.naming.WsnInitialContextFactory</prop>
        </props>
      </property>
    </bean>

    implementation.spring 的 SCA 儲存器不會在 Java EE 儲存器中執行,因此它無法存取 Java EE 本端 JNDI 名稱空間。 透過指定 Spring Bean 使用 WebSphere 起始環境定義 Factory ,您可以在查閱期間防止 java:comp/ext 附加到 JNDI 名稱前面。

關於這項作業

您可以使用 Spring 應用程式環境定義作為 SCA 組合元件內的實作。 使用 Spring 2.5.5來定義實作。 Spring 應用程式環境定義提供完整複合的公開服務,並使用 SCA 來使用參照。

將 Spring 用於實作的元件可以佈線 SCA 服務和參照,而不會將 SCA meta 資料引進 Spring 配置中。 一般而言, Spring 環境定義很少瞭解 SCA 環境。

程序

  1. 定義在複合定義中使用 Spring Framework 的元件實作。

    複合定義中的 Spring 元件實作具有下列格式:

    <implementation.spring location="targetURI"/>

    元素的 location 屬性指定目錄的目標統一資源指示器 (URI) ,或包含 Spring 應用程式環境定義檔的完整路徑。

    有兩種方法可以在 location 屬性中指定目標 URI:

    • 指定完整路徑:
      <implementation.spring location="./spring/application-context.xml"/>
    • 指定目錄:
      <implementation.spring location="./spring"/>

      目標 URI 將資源指定為名為 spring的目錄,其中包含所有 Spring 相關檔案。 若要指向一個應用程式環境定義,該目錄中的 META-INF/MANIFEST.MF 檔案必須包含格式為 Spring-Context: pathSpring-Context 標頭,其中 path 是相對於位置 URI 的相對路徑。 例如:

      Spring-Context: META-INF/spring/application-context.xml

      如果 META-INF/MANIFEST.MF 檔不存在或不包含 Spring-Context 標頭,則產品會使用 META-INF/spring 目錄中的 application-context.xml 檔來建置應用程式環境定義。 如果 META-INF/spring/application-context.xml 檔不存在,則應用程式不會進行部署。

  2. 選用: 置換 Spring 資源至 SCA 資源的隱含對映。

    依預設, SCA 會隱含地將 Spring 資源對映至 SCA 資源,如下所示:

    • 每一個 <bean/> 都會變成 <sca:service/>
    • 如果由介面輸入,則每一個未解析的 <property/> 都會變成 <sca:reference/>
    • 如果不是由介面輸入,則每一個未解析的 <property/> 都會變成 <sca:property/>

    您可以在 Spring 環境定義中使用 SCA XML 延伸來建立明確宣告,以置換此預設對映。 您通常會這麼做,讓 Spring 儲存器能夠利用例如 Spring Aspect-Oriented Programming (AOP) 來裝飾 Bean。 SCA XML 延伸定義如下:

    • <sca:service/> 定義環境定義所公開的每一個服務。
    • <sca:reference/> 定義環境定義所公開的每一個參照。
    • <sca:property/> 定義環境定義所公開的每一個內容。<sca:property/> 必須是 Bean 類別,而不是初始類型。

    例如,下列 Spring 配置中定義的 checkingAccountService、 calculatorService和 stockQuoteService 內容,在 Spring 應用程式環境定義中使用 <sca:reference> 元素明確宣告為 SCA Bean:

    <beans>
      <bean id="AccountServiceBean" class="bigbank.account.AccountServiceImpl">
        <property name="calculatorService" ref="calculatorService"/>
        <property name="stockQuoteService" ref="stockQuoteService"/>
        <property name="checkingAccountService" ref="checkingAccountService"/>
        <!-- Some implicit references and properties follow. A property with a reference
             not satisifed * within the Spring application context. -->
        <property name="savingsAccountService" ref="savingsAccountService"/>
        <property name="stockAccountService" ref="stockAccountService"/>
        <property name="currency" value="EURO"/>
      </bean>
      <sca:reference name="checkingAccountService" type="bigbank.account.checking.CheckingAccountService"/>
      <ca:reference name="calculatorService" type="bigbank.calculator.CalculatorService"/>
      <sca:reference name="stockQuoteService" type="bigbank.stockquote.StockQuoteService"/>
    </beans>
  3. 如果您已完成 步驟 2,若要使用 SCA XML 延伸,您必須將 SCA 綱目新增至應用程式環境定義。

    將 SCA 綱目 https://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd 新增至應用程式環境定義。 指定 Spring 應用程式環境定義,以定義 SCA 綱目名稱空間,並讓 Spring 應用程式知道 SCA 相關的 Bean; 例如:

    <beans xmlns="https://www.springframework.org/schema/beans"
           xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
           xmlns:sca="https://www.springframework.org/schema/sca"
           xsi:schemaLocation="
             https://www.springframework.org/schema/beans
             https://www.springframework.org/schema/beans/spring-beans.xsd
             https://www.springframework.org/schema/sca
             https://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd">
      <sca:service name="StockQuoteService"
           type="bigbank.stockquote.StockQuoteService" target="StockQuoteServiceBean"/>
      <bean id="StockQuoteServiceBean" class="bigbank.stockquote.StockQuoteImpl">
      </bean>
    </beans>

    如需定義應用程式環境定義的相關資訊,請參閱 Spring 來源社群所提供的參考文件。 如需 SCA 綱目的相關資訊,請參閱 SCA Spring 實作規格。

  4. 將服務 Java 保存檔 (JAR) 中的 SCA 應用程式環境定義檔包裝在複合定義中指定的位置。

    例如,將 SCA 應用程式環境定義檔包裝在名為 helloworld-spring.jar的 Spring 服務 JAR 檔中。

  5. 建立包含 Spring 及產品 SCA 執行時期檔案的 Spring 執行時期 JAR 檔。

    由於產品未隨附 Spring 執行時期二進位檔,您必須建立一個包含三個 Spring 架構 JAR 檔和一個產品 JAR 檔的資產。 建立資產,如下所示:

    1. 如果您沒有 Spring 2.5.5 架構二進位檔,請移至 Spring Community Downloads ( https://www.springsource.com/download/community?project= ) ,並下載 spring-framework-2.5.5.zip

      下載壓縮的 .zip 檔案之後,將它解壓縮至暫存目錄。

    2. 建立空目錄; 例如 C:\SpringAsset
    3. 將 Spring 2.5.5 架構二進位檔 spring-beans.jarspring-context.jarspring-core.jar 複製到空目錄。

      如果 Spring 應用程式需要交易支援,請將所有 Spring JAR 檔複製到空白目錄。 交易支援也需要 AspectJ Weaver 程式庫檔案。

    4. app_server_root/optionalLibraries/sca/SCA-implementation-spring-runtime-1.0.1.jar 檔複製到您放置三個 Spring JAR 檔的相同目錄。
      避免麻煩: 如果您安裝產品維護套件,請使用較新版本的 app_server_root/optionalLibraries/sca/SCA-implementation-spring-runtime-1.0.1.jar 檔案來更新 SpringSharedLibAsset.jar
    5. 建立名為 SpringSharedLibAsset.jar 的 JAR 檔,其中包含您放置在 C:\SpringAsset 目錄中的四個 JAR 檔。

      例如,在命令提示字元中,輸入下列指令:

      1. cd C:\SpringAsset
      2. jar -cvf SpringSharedLibAsset.jar *.jar

      基於效能原因, JAR 檔必須命名為 SpringSharedLibAsset.jar

    6. 驗證 SpringSharedLibAsset.jar 檔案在根目錄中包含全部四個 JAR 檔。
  6. 將 Spring 執行時期 JAR 檔匯入為資產。

    若要使用 wsadmin Jython 指令將 SpringSharedLibAsset.jar 匯入為資產,請輸入下列指令:

    AdminTask.importAsset('-source SpringSharedLibAsset.jar -storageType FULL')

    您也可以使用管理主控台。

  7. 將 Spring 服務 JAR 檔匯入成與 Spring 執行時期資產有相依關係的資產。

    假設您的 Spring 服務 JAR 檔命名為 helloworld-spring.jar。 匯入 Spring 服務 JAR 檔 helloworld-spring.jar,並在 Spring 執行時期資產 SpringSharedLibAsset.jar上建立相依關係。 此相依關係可讓產品存取必要的 Spring 類別。 您可以使用下列 wsadmin Jython 指令來匯入 Spring 服務 JAR 檔:

    AdminTask.importAsset('-source helloworld-spring.jar -storageType FULL -AssetOptions
     [[ helloworld-spring.jar helloworld-spring.jar "" "" "" spec=zip assetname=SpringSharedLibAsset.jar
     "" false]]]')

    或者,您可以使用管理主控台來匯入具有相依關係的資產:

    1. 在管理主控台上,按一下 應用程式 > 應用程式類型 > 資產
    2. 在「資產」頁面上,按一下 匯入
    3. 在「上傳資產」頁面上,指定服務 JAR 檔的完整路徑名稱,然後按 下一步
    4. 在「選取匯入資產的選項」頁面上,指定相依關係。
      1. 按一下管理關係。 產品會比對 JAR 資訊清單中定義的相依關係與已匯入管理網域的資產,以自動偵測資產關係。
      2. 選取您的 Spring 執行時期 JAR 檔,例如 SpringSharedLibAsset.jar,按一下 >> ,將 JAR 檔移至 已選取 清單。
      3. 按一下確定

        現行資產關係下,會顯示資產名稱; 例如:

        WebSphere:assetname=SpringSharedLibAsset.jar
      4. 下一步
    5. 按一下完成
    6. 在產品匯入資產之後,請按一下 儲存

結果

Spring 執行時期 JAR 檔和 Spring 服務 JAR 檔是匯入的資產,可在商業層次應用程式中使用。 Spring 服務 JAR 資產與 Spring 執行時期資產有相依關係。

下一步

將您建立的 JAR 資產新增至 SCA 商業層次應用程式。

若要瞭解產品支援但未在 SCA Spring 實作規格中定義的 Spring 實作特性,請參閱其他 Spring 元件的實作特性相關主題。