Forums: Open Discussion (Thread #22653)

【バッチFW】親クラス作成方法 (2009-05-07 16:10 by Anonymous #43639)

お世話になっております。
バッチフレームワークでは、バッチ起動時にxml定義ファイルを読み込み、
設定内容を元にDI(注入)を行い、各処理が動くと考えていますが、
業務仕様で似た仕様のものがあるため、
PreLogic, BLogic, PostLogicの各クラスに親クラスを作成しようと考えています。
(1例を挙げるとメッセージはどのクラスでも使用するので、親クラスでDIしたい)

親クラス用にDI設定ファイル(xml)を作成し、DIさせる場合、xmlファイル作成後に
どこに配置し、どのような設定を行えばよいのでしょうか?

Reply to #43639×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 【バッチFW】親クラス作成方法 (2009-05-07 17:08 by ahn #43642)

xmlの配置場所はbatchapps上に業務用のフォルダを作成し配置することをお勧めします。
例)batchapps/sample/sampleDI.xmlなど
定義方法については以下の例をご参照ください。(BLogicの例)
<!--ビジネスロジック:Bean定義のサンプル-->
<bean class="jp.co.nttdata.my_test.JB0002_SUB_BLogic" id="blogic" parent="parentBlogic" />

<!--ビジネスロジック:親クラスのBean定義サンプル-->
<bean class="jp.co.nttdata.my_test.JB0002BLogic" id="parentBlogic" abstract="true">
<property name="testString" value="AAAAAAAAAA"/>
</bean>

<!--JB0002BLogic:BLogic親クラスのサンプル-->
public class JB0002BLogic implements BLogic<String, JobContext> {

/**
* ログインスタンス。
*/
private static Log log = LogFactory.getLog(JB0002BLogic.class);


protected String testString = "BBBBBB";

/**
* ビジネスロジック
*
* @param data コレクタ結果クラス
* @param jobContext ジョブコンテキストクラス
* @return ビジネスロジックの実行結果、BLogicResultインスタンス。
*/
public BLogicResult execute(String data, JobContext jobContext) {

log.error("################################# IN : " + data.toString());

return new BLogicResult(ReturnCode.NORMAL_END);
}

/**
* @param testString 設定する testString
*/
public void setTestString(String testString) {
this.testString = testString;
}

/**
* @return testString
*/
public String getTestString() {
return testString;
}
}

<!--JB0002_SUB_BLogic:BLogic子クラスのサンプル-->
public class JB0002_SUB_BLogic extends JB0002BLogic {

/**
* ログインスタンス。
*/
private static Log log = LogFactory.getLog(JB0002_SUB_BLogic.class);


/**
* ビジネスロジック
*
* @param data コレクタ結果クラス
* @param jobContext ジョブコンテキストクラス
* @return ビジネスロジックの実行結果、BLogicResultインスタンス。
*/
public BLogicResult execute(String data, JobContext jobContext) {

log.error("################################# IN : " + super.getTestString());

return new BLogicResult(ReturnCode.NORMAL_END);
}

}

親クラスの設定を別xmlに定義し、各ジョブBean定義ファイルのインポートさせると
一つの定義情報を使いまわすことができます。
例)<import resource="classpath:sample/sampleDI.xml"/>

Reply to #43639

Reply to #43642×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 【バッチFW】親クラス作成方法 (2009-05-07 18:03 by Anonymous #43643)

とても分かり易いサンプルをありがとうございます。
親クラス用のxmlファイルを別定義にして、実装できました。
Reply to #43642

Reply to #43643×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login