IJServer間連携機能は、Spring Frameworkアプリケーションから別プロセスのIJServerへ配備されたSpring Frameworkアプリケーションの呼び出しを実現します。
本機能を利用することにより、アプリケーションを分離することが可能になるため、負荷分散などのスケーラブルな運用ができます。
IJServer間連携機能によるSpring Frameworkアプリケーションの構成および呼び出しの流れを以下に示します。
図8.3 リモート呼び出し機能によるIJServer間連携機能の構成図
IJServer間連携機能を利用したSpring Frameworkアプリケーションの開発
IJServer間連携機能を利用したSpring Frameworkアプリケーションを開発するために、開発者は「Springプロジェクト・ネイチャーの追加を行ったWebアプリケーションプロジェクト」と「Spring Project」または「Springプロジェクト・ネイチャーの追加を行ったjavaプロジェクト」を作成します。
「Springプロジェクト・ネイチャーの追加を行ったWebアプリケーションプロジェクト」にて、WEB層の資材と定義ファイルをWARファイルにまとめます。
「Spring Project」または「Springプロジェクト・ネイチャーの追加を行ったjavaプロジェクト」にて、AP層の資材と定義ファイルをjarファイルにまとめます。
最後にエンタープライズアプリケーションプロジェクトを作成し、jarファイルをEARファイルにまとめます。
作成するエンタープライズアプリケーションは、以下の構成にする必要があります。
EARファイルの構成図
ポイント
“8.3 Spring Frameworkアプリケーションの開発”の例を元に、アプリケーションを作成します。
Web層のサーバアプリケーションを“Webアプリケーション”、 AP層のサーバアプリケーションを“業務アプリケーション”とします。
業務アプリケーションの開発(AP層の作成)
以下のアプリケーションを作成します。
EmployeeDao.java(DAOのインタフェース)
EmployeeDaoImpl.java(DAOの実装クラス)
ListService.java(業務アプリケーションのインタフェース)
ListServiceImpl.java(業務アプリケーションの実装クラス)
AopDatabaseCheck.java(AOPで差し込む処理)
アプリケーションの作成例は、“8.3 Spring Frameworkアプリケーションの開発”を参照してください。
注意
IJServer間連携機能にてユーザ定義クラスを利用する場合、クラスをシリアライズする必要があります。
Webアプリケーションの開発(Web層の作成)
以下のアプリケーションを作成します。
ViewEmployeeListController.java(社員一覧を表示するコントローラ)
ViewEmployeeList.jsp(社員一覧を表示するビュー)
アプリケーションの作成例は、“8.3 Spring Frameworkアプリケーションの開発”を参照してください。
注意
IJServer間連携機能にてユーザ定義クラスを利用する場合、クラスをシリアライズする必要があります。
また、業務アプリケーションで作成したインタフェースを用意します。
ListService.java(業務アプリケーションのインタフェース)
定義ファイルの作成
業務アプリケーションのBean定義ファイルを作成
IJServer間連携機能によって呼び出される業務アプリケーションのBean定義ファイルを作成します。
■applicationContext.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" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <aop:config> <aop:aspect id="sample" ref="sampleAdvice"> <aop:around pointcut-ref="pc1" method="aroundMessage" /> <aop:pointcut expression="execution(* execDao*())" id="pc1" /> </aop:aspect> </aop:config> <bean id="sampleAdvice" class="test.AopDatabaseCheck"/> <!-- Webアプリケーションから呼び出される業務アプリケーションのBean定義 --> <bean id="remoteBusinessService" class="test.ListServiceImpl"> <property name="employeeDao" ref="employeeDao00"/> </bean> <bean id="employeeDao00" class="test.EmployeeDaoImpl"/> </beans> |
WebアプリケーションのBean定義ファイルを作成
IJServer間連携機能を動作させるために、WebアプリケーションのBean定義ファイルを作成します。
■applicationContext.xmlまたはサーブレット名-servlet.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" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <bean id="viewController" class="test.ViewEmployeeListController" /> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/index.html">viewController</prop> </props> </property> </bean> <!-- (1) IJServer間連携機能を動作させるためのBean定義 --> <bean id="businessService" class="com.fujitsu.interstage.apfw.springframework.ejb.access.RemoteStatelessSessionProxyFactoryBean"> <!-- 業務アプリケーションのBeanIdを定義します --> <property name="beanId" value="remoteBusinessService"/> <!-- 業務アプリケーションのインタフェースを定義します --> <property name="businessInterface" value="test.ListService"/> </bean> </beans> |
(1) IJServer間連携機能を動作させるためのBean定義
IJServer間連携機能のクラス“com.fujitsu.interstage.apfw.springframework.ejb.access.RemoteStatelessSessionProxyFactoryBean”を指定します。
Webアプリケーションから呼び出す業務アプリケーションのBeanIdを定義します。(業務アプリケーションのBean定義ファイルに記述したBeanIdと同じにします)
業務アプリケーションのインタフェースを定義します。
注意
上記で定義したインタフェースと同じものを、Webアプリケーションにも格納してください。
クラスファイルのパッケージ化
EARファイルの作成
業務アプリケーションやBean定義ファイルはEARファイルとして作成します。
また、作成するEARファイルにはIJServer間連携機能のモジュールを同梱する必要があります。
EARファイルを作成する方法を以下に示します。
EARファイル配下にShared/libディレクトリを作成し、業務アプリケーションとBean定義ファイルを圧縮したjarファイルを格納します。
EARファイル配下にIJServer間連携機能のモジュールを格納します。
IJServer間連携機能のモジュールは以下のディレクトリに格納されています。
[Interstageのインストールディレクトリ]\BAS\spring25\lib\apfw-spring-ejb-api.jar |
/opt/FJSVibs/spring25/lib/apfw-spring-ejb-api.jar |
EARファイルのMETA-INFディレクトリ配下に以下のdeployment descriptor(application.xml)を格納します。
◆application.xml
<?xml version="1.0" encoding="UTF-8"?> <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4"> <module> <ejb>apfw-spring-ejb-api.jar</ejb> </module> </application> |
EARファイルの作成の詳細に関しては、“Interstage Application Server/Interstage Web Server J2EEユーザーズガイド(旧版互換)”を参照してください。
WARファイルの作成
WebアプリケーションやBean定義ファイルをWARファイルとして作成します。
WARファイルの作成の詳細に関しては、“Interstage Application Server/Interstage Web Server J2EEユーザーズガイド(旧版互換)”を参照してください。
IJServerの設定
IJServer間連携機能を利用する場合には、Webアプリケーションを運用するIJServerと業務アプリケーションを運用するIJServerでそれぞれ異なる設定を行う必要があります。
以下にIJServer間連携機能を利用する場合のIJServerの設定について説明します。
Webアプリケーションを運用するIJServerの設定
Webアプリケーションを運用するIJServerのクラスパスにSpring Frameworkの機能が動作するために必要なjarファイルとIJServer間連携機能のjarファイルを設定します。
Spring Frameworkの機能が動作するために必要なjarファイルの設定については“8.2 Spring Frameworkの環境作成”を参照してください。
◆クラスパスの設定
Interstage管理コンソールを使用して、IJServer間連携機能のjarファイルをクラスパスへ設定します。
[システム] > [ワークユニット] > “ワークユニット名” > [環境設定]タブ
以下のjarファイルを設定します。
[Interstageのインストールディレクトリ]\BAS\spring25\lib\apfw-spring25.jar |
/opt/FJSVibs/spring25/lib/apfw-spring25.jar |
業務アプリケーションを運用するIJServerの設定
業務アプリケーションを運用するIJServerのクラスパスにSpring Frameworkの機能が動作するために必要なjarファイルとIJServer間連携機能のjarファイルを設定します。
Spring Frameworkの機能が動作するために必要なjarファイルの設定については“8.2 Spring Frameworkの環境作成”を参照してください。
◆クラスパスの設定
Interstage管理コンソールを使用して、IJServer間連携機能のjarファイルをクラスパスへ設定します。
[システム] > [ワークユニット] > “ワークユニット名” > [環境設定]タブ
以下のjarファイルを設定します。
[Interstageのインストールディレクトリ]\BAS\spring25\lib\apfw-spring-ejb-impl.jar |
/opt/FJSVibs/spring25/lib/apfw-spring-ejb-impl.jar |
アプリケーションの配備
作成したWARファイルまたはEARファイルをInterstage管理コンソールから配備を行います。
注意
EJBアプリケーション名を変更してEARファイルを配備した場合、IJServer間連携機能を利用するには、WebアプリケーションのBean定義ファイルにEJBアプリケーション名を定義する必要があります。
EJBアプリケーション名を“sampleEjb”に変更した場合の例を以下に示します。
<?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:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> ・・・ <!-- IJServer間連携機能を動作させるためのBean定義 --> <bean id="businessService" class="com.fujitsu.interstage.apfw.springframework.ejb.access.RemoteStatelessSessionProxyFactoryBean"> <!-- 業務アプリケーションのBeanIdを定義します --> <property name="beanId" value="remoteBusinessService"/> <!-- 業務アプリケーションのインタフェースを定義します --> <property name="businessInterface" value="test.ListService"/> <!-- EJBアプリケーション名を定義します --> <property name="jndiName" value="sampleEjb"/> </bean> ・・・ </beans> |
Interstage管理コンソールの操作方法については、“Interstage Application Server/Interstage Web Server J2EEユーザーズガイド(旧版互換)”を参照してください。
ネーミングサービスの設定
業務アプリケーションがWebアプリケーションとは別のマシン環境にある場合、ネーミングサービスの設定を行う必要があります。
◆ネーミングサービスの設定
Interstage管理コンソールを使用して、ネーミングサービスを運用するマシンのホスト名を設定します。
[システム] > [環境設定]タブ > 詳細設定 > ネーミングサービス詳細設定
ネーミングサービスの設計については、“Interstage Business Application Server セットアップガイド”を参照してください。