sastruts でstruts 設定ソースを 動かしてみる - …...seasar strutsのメリット...
TRANSCRIPT
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.1
Seasar Conference 2009 Spring
Seasar Conference 2009 Spring
Seasar
SAStrutsおさらいと
SAStrutsでStruts設定ソースを動かしてみる
2009年06月
Seasar カンファレンス 2009 春
2Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar メニュー
自己紹介
SAStrutsのおさらい
なぜSAStruts上でStruts設定?
Demo
Seasarプロダクト群の紹介
まとめ
3Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar 自己紹介
• 名前: 新田 智啓(しんでん ともひろ)
• ブログ: http://d.haneta.ne.jp/newta/
• 所属: 自由と束縛の狭間→ 無職!
(株式会社フルネス入社予定)
• 活動
– SAStrutsコミッタ(一応)
– S2Csvコミッタ
– JavaSTHフレームワーク
ちなみにこれ私が描いた落書き。名前はシーサーキングくん
4Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsのおさらい
SAStrutsの
おさらい
5Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsのおさらい
と、その前に
6Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar Strutsのおさらい
Strutsの
おさらい
7Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar その前にStrutsのおさらい
• Strutsとは–Javaでディファクトスタンダードな
Webフレームワーク
–現場開発者よりもマネージャ的に使いやすい
–シンプルなでフレームワークとして出過ぎない適度なつくり
8Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar マネージャ的にStrutsは・・・
• マネージャ的に使いやすいStrutsを使ったことがある人が多い
→ 人を集めやすい
デファクトである
→ 無難、実績がある
情報が多い
→ 日本語情報、書籍
9Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar 現場開発者よりも
「現場開発者よりもマネージャ的に使いやすい」
10Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar よりも!
現場開発者よりも
11Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar 現場開発者の不満
「よりも」
→現場開発者の不満
12Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar Strutsの現場開発者の不満
→現場開発者の不満• 設定ファイル地獄(struts-config.xml、validation.xml)
• 設定ファイルとクラスの関連の再定義• ソースコード修正時の再起動• テストがしにくい...など
13Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStruts登場
そこで!
SAStruts登場
14Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar Strutsを補うSAStruts
現場開発者の不満の解決!• 設定ファイル地獄
→ 設定ファイル未編集
• 設定ファイルとクラスの関連の再定義→ クラスファイルからの自動組立
• ソースコード修正時の再起動→ HotDeployによる再起動なしの修正の反映
• テストがしにくい→POJOなActionクラス
...など
15Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar Strutsのメリットのメリットは
ではマネージャ的に使いやすい.
人を集めやすい
無難、実績がある
日本語情報、書籍
と言われていた
Strutsのメリットは
SAStrutsでどうなったか?
16Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar Strutsのメリットはそのまま
人を集めやすい
→ Strutsの考え方が同じ(必要なスキルが同じ)
(ActionやFormの考え方やロジックの流れ)
無難、実績がある
→ 別セッション
日本語情報、書籍
→ Seasarプロダクトは日本発
SAStruts関連の書籍も
ファウンデーション公認の本が発売済み
17Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsメリットのまとめ
SAStrutsはStrutsのメリットはそのままに
デメリットを消し去っている
プロダクト
18Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStruts使い方
SAStrutsの使い方
ちょっとだけおさらい
19Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsのおさらい(使い方)
SAStrutsにおける基本的機能• URLとActionクラスの関連付け
• 簡単なValidationの場合
• 色々なチェックを行うValidationの場合
20Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar
package tutorial.action;
public class HelloWorldAction {
@ActionForm
public HelloWorldForm helloWorldForm;
@Execute(validator = false)
public String hello() {
helloWorldForm.message = “Hello World!”;
return “hello.jsp”;
}
}
SAStrutsのおさらい(使い方)
• URLとActionクラスの関連付け
http://localhost:8080/sa-struts-tutorial/helloWorld/hello
アプリケーション名
アクションクラス名
メソッド名
遷移先パス
21Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsのおさらい(使い方)
• Validationの指定1(簡単なもの)• アノテーションで指定
package tutorial.form;
public class HelloWorldForm {
@Required
public String arg1;
@IntegerType
public String arg2;
public String message;
}
22Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsのおさらい(使い方)
• Validationの指定2(いろいろするとき)• メソッドでチェックpackage tutorial.action;
public class HelloWorldAction {
@Execute(validate = “checkMethod”)
public String submit() {
return “checkOK.jsp”;
}
public ActionMessages checkMethod() {
ActionMessages errors = new ActionMessages();
・・・
return errors ;
}
}
23Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar ちょっとだけTIPS(図)
Action
Form
Service
Entity or Dto
URL
Call
DI
DB
BeanUtil
基本図
24Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar ちょっとだけTIPS(Form)
• FormクラスはServiceクラスに渡さない
–画面データ情報である
–Formクラスのメンバは全てStringにしておく
• (バリデーションされていないデータも保存)
–ActionでDtoに詰め替える
–Form、Dtoの詰め替えはBeanUtilを利用
25Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar ちょっとだけTIPS(Action)
• 入力系、出力系のメソッドは分ける
–入力系はRedirectすると良い
• (ブラウザのF5[更新]対策)
–出力系はDBからデータを取ってきて表示のみ
–出力系はバリデーションしない
–メソッド名で分かるようにしておくと便利(入力系はdoXxxxとするなど。)
26Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar やっときた
やっときた、
SAStrutsで
Struts設定を動かす
27Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar Struts動作のAddOn
まず、SAStruts上でStrutsの設定で
動かすためのAddonを作りました
これを追加することでStrutsの設定ファイルを読み込ませて
動作させることが出来ます
28Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar AddOn
とりあえず
Strutsの設定で
何とかかんとかと言う説明がめんどいので
このStruts設定で動くAddonに
名前を付けました
29Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsAOS
SAStrutsAOS
Additional Original Style
と名づけてみた
30Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsAOSってどんなもの?
• どんな動き?–SAStrutsでは処理しないようになっている
Strutsの設定ファイルのstruts-config.xmlにあるaction-mappingやform-beanの定義も読み込みます
–struts-config.xmlで読み込んだ設定はSAStrutsの処理ではなく、Strutsの処理で動作します
これがポイント!
31Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsAOSって
まとめるとstruts-config.xmlで読み込まれた設定は
Strutsで動作し、SAStrutsの配置ルールで設定された
ActionクラスはSAStrutsで動く
32Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar すると何が出来るか
• うれしいこと
–Strutsの資産はそのまま動かして新しく作る部分はSAStrutsで作れる
–Strutsがそのまま動くため新規開発でなくても改修時にSAStrutsでの開発を提案できる
–SAStrutsを利用して作る部分は各種Seasar
プロダクトと簡単に連携できる
–SessionやRequestなどが共有できる
–Struts技術スキルだけでなくStrutsのソースそのものを再利用できる(かも)
33Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar 利点をまとめると
SAStrutsAOSの利点• SAStrutsで作れる→開発者にやさしい
• 提案できる→コストと現場理想の間の現実路線
• 連携できる→便利なS2プロダクト付
• 共有できる→小細工なしで共有可能
• 再利用できる→今ある資産を無駄にしない
34Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar 注意すべき所
• 使用上の注意–AddonのJarを追加することにより動きます
–SAStrutsの正式のものではない• (要望、フィードバックによっては正式にSAStrutsのリポジトリに入れることも考えるかも)
–SAStrutsとStruts部分が入るためプログラムとしてきれいな形ではない–(コストと理想の現実路線を拾ったプロダクト)
• (Struts動作の互換を優先しているためSeasarコンテナにコンポーネント管理していない、HotDeployも出来ない)
–動作StrutsのバージョンはSAStrutsの利用しているStruts1.2.9
35Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsAOS動作イメージ
SAStrutsAOSの
動作イメージ図
36Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsAOSの図(設定ファイル)
SAStrutsAOSの動き設定ファイル読込時
validation.xmlvalidation.xml
struts-config.xml
Formクラス
Actionクラス
Struts
SAStruts
SAStrutsAOS
設定
設定
HotDeploy時はStruts設定をキャッシュ
※注 これは簡略化したイメージ図です実際にはSAStrutsとStrutsはもっと相互に連携して実行されます
37Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar SAStrutsAOSの図(Action実行)
SAStrutsAOSのAction実行時
Request
Struts
SAStruts
SAStrutsAOS
設定
SAStruts関連クラスの場合SAStrutsメソッドCall
それ以外の場合StrutsメソッドCall
URL
Response
or
Forward
or
Redirect
※注 これは簡略化したイメージ図です実際にはSAStrutsとStrutsはもっと相互に連携して実行されます
38Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar では、使い方
使い方
39Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar 使い方
• SAStrutsのプロジェクトをベースにします– (Doltengでプロジェクト作成をしてください)
• StrutsAOSのJarをダウンロードhttp://sourceforge.jp/projects/javasth/docs/sa-struts-aos.jar/ja/3/sa-struts-aos.jar
• クラスパスにjarを追加
• web.xmlとstruts-config.xmlに設定してある– S2ModuleConfigFactory
– S2RequestProcessor
– S2ValidatorPlugIn
↓
– S2AOSModuleConfigFactory
– S2AOSRequestProcessor
– S2AOSValidatorPlugIn
に変える。
Packageも同じ位置にしたので修正簡単
40Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar アプリ構成
• 旧Struts資産と新規に追加するSAStruts資産のパッケージは分けておく
• 旧Struts資産と新規SAStrutsのServiceクラス利用時などにトランザクション管理やコンポーネント管理に注意する。
– (あまり混ぜて使わない)
• 共有するものはSessionやRequest、DB。
– (ほかクラス群についてはUtil系クラス、計算のみのロジック系クラスに抑えたほうがはまらないかも)
41Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar Demo
■Demo
Struts
↓
StrutsAOS
(Struts & SAStruts)
42Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar Seasar連携
Seasar(SAStruts)
を導入することで
連携できる
Seasarプロダクト
43Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar Seasarプロダクト
• O/Rマッピング• S2Dao
• S2JDBC
• ツール(pluginなど)
• Dolteng
• DBFlute
• S2JDBC-Gen
• Viewエンジン• Mayaa
•Sandbox
• バッチフレームワーク• S2Chronos
• Mail送信
• S2Mai
• Excel出力
• S2Fisshplate
44Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar
まとめ
まとめ
45Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar
SAStrutsAOSで手軽に既存StrutsシステムにSAStrutsで追加してみよう
SAStrutsAOSまとめ
46Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar
Strutsから SAStrutsでSeasarプロダクトの第一歩を
!
Seasarプロダクトの第一歩を
47Seasar Conference 2009 Spring
Copyright© 2004-2009 The Seasar Foundation and the others. All rights reserved.
Seasar
ご清聴ありがとうございました
感謝