weblogic + springframework 最新事例「第5回weblogic server勉強会@東京」資料
DESCRIPTION
第5回WebLogic Server勉強会@東京の資料です。当資料は講演者 日本Springユーザ会会長長谷川裕一 氏の資料です。TRANSCRIPT
第5回WebLogic Server勉強会@東京
資料
2009年11月27日合同会社Starlight&Storm
Javaアプリケーションプロジェクトを成功に
導くための肝
Webアプリケーションの改善
Springを使ったアーキテクチャ・リファクタリング
2
問題外のWebアプリ
• 時々見かけるパターン
• 機能追加はクラスの追加
– 重複コードが山ほど存在
• Unitテストは99.999%おこなっていない
• 設計書も99.999%ない。UMLでの記述など論外
3
FindAction Oracle
ブラウザ
FindEmployee
真面目に作ったWebアプリ
• 自前で真面目に作ったWebアプリ
• 設計的には問題なし– 色々作り込むのは面倒
• Unitテストやメンテナンスに問題
4
FindAction<<Singleton>>
EmployeeServiceImpl
<<Singleton>>EmployeeDaoOracle
Oracle
ブラウザ
EmployeeDao
EmployeeService
Factory
生成生成利用利用
5
public class EmployeeServiceImplimplements EmployeeService{
・・・ public List findAll() throws Exception {
if(Log.flag) { System.out.println(“***Start”); }Connection conn = null;・・・EmployeeDao dao
= (EmployeeDao)Factory.create(KEY);List employeeList = null;try {
employeeList = dao.findAll(conn);conn.commit();
} catch(Exception e) {conn.rollback();・・・
} finally {conn.close();・・・
}if(Log.flag) { System.out.println(“***End”); }return employeeList;
}
・・・
真面目なWebアプリのSource
• 分岐が多いため、Unitテストが困難
• 共通化できる部分が未分離
• 例外処理とConnectionの引き渡しが連続性を阻害EmployeeServiceImpl
共通部品を導入してても…
• 共通処理の実装が面倒
• 共通処理の使い方を覚える必要がある
• …etc
6
public class EmployeeServiceImplimplements EmployeeService{
・・・ public List findAll() throws Exception {
log.start();Connection conn = null;
・・・EmployeeDao dao
= (EmployeeDao)Factory.create(KEY);List employeeList = null;try {
conn = transaction.start();employeeList = dao.findAll(conn);
transaction.commit(conn);} catch(Exception e) {transaction.rollback(conn);
}log.end();return employeeList;
}
・・・
EmployeeServiceImpl
TransactionClass
UtilityClass
Springを利用したWebアプリ
• Factoryを実装する必要がない– クラス(開発者)はDIコンテナに依存しない
• 共通処理はAOPで後から追加
– ソースコードには記述しない
7
FindAction EmployeeServiceImpl
EmployeeDaoOracle Oracle
ブラウザ
EmployeeDao
EmployeeService
Spring
生成生成
InjectionInjection
TransactionClass
UtilityClass
Springを利用したWebアプリのSource
• 作るの簡単
• Unitテストも簡単
8
public class EmployeeServiceImpl implements EmploeeService {
@Autowiredprivate EmployeeDao dao;
public List findAll() {return dao.findAll();
}・・・
書くことがなくなりました・・・
メンテナンス性が重要
• エンタープライズ系のシステムはメンテナンス性が重要
– システムの寿命は長い
– 機能追加/変更は頻繁に発生する
9
経過時間
価値
従来の考え方
ビジネス環境の変化
機能追加
大きな障害
機能変更
障害の修正
Springの利用事例(国内)
• JSUG調べ(2006/4)– Webアプリ(イントラ)や社内フレームワークなど
• 最近の利用傾向
– 大規模ミッションクリティカルな案件での利用が増加
– 大手SIerのフレームワークのベースとして利用
– OLTPだけでなくバッチでも利用
– 技術的な傾向
• リッチクライアントの利用、レガシーシステムとの統合
– 今後の注目• SpringDM(OSGi)、Grails
10
WebLogicとSpring
• Springはサポート対象です
– WebLogic 8.1~• WebLogic Server 10g Release 3 (10.3)
– SpringFramework 2.0.2
• OTNの「BEA WebLogic Server でサポート
対象のコンフィグレーション」ページからサポート対象をたどってください
11
経験を重ねて最近、分かってきたこと
こういうことを伝えてきた
こんなことになっていた
維持するのがやっと機能追加や変更を加えると…
Javaフレームワークで生産性向上
Struts + SpringFramework連携
14
Struts• 国内ではMVCフレームワークのデファクトスタンダー
ド– Apacheプロジェクト
– 根強い人気の 1.x と、イマイチ人気がない 2.x
Struts Action
定義ファイル
JSP(Tag)
ActionForm
Model
15
Struts1.x + Spring1.x 連携
• リクエストプロセッサを置き換える方法がお薦め– AutowiringRequestProcessor
Spring
生成
Struts XxxAction ServiceImpl
イベント
注入
struts-config.xml
struts-config.xml
applicationContext.xmlapplicationContext.xml
この関連が問題この関連が問題
生成
生成
16
AutowiringRequestProcessor
・・・<controller processorClass
="org.springframework.web.struts.AutowiringRequestProcessor" />・・・
・・・<controller processorClass
="org.springframework.web.struts.AutowiringRequestProcessor" />・・・
struts-config.xml
Actionクラス
public class HelloAction extends Action {private HelloService hello;・・・public void setHelloService(HelloService hello) {this. hello = hello;
}・・・
public class HelloAction extends Action {private HelloService hello;・・・public void setHelloService(HelloService hello) {this. hello = hello;
}・・・
RequestProcessorの置き換え。
この他に、ActionFormだと
か、定義ファイルに記述する内容も多くて、ここに書ききれないくらい大変!
17
Struts2.x + Spring2.x 連携(1)
• Struts2は、Struts1.xとWebWork2(DIコンテ
ナ付き)が合体したもの– ActionはPOJOとして作成可能
– 定義ファイルは最小限(もしくは不要)• JSPはcontentフォルダに配置
• Actionクラスは、actionフォルダに配置
• xxxActionという名前で、xxx.jspが呼ばれる
• etc...– そして、Easy Spring integration!
18
Struts2.x + Spring2.x 連携(2)
• struts-spring-plugin-x.x.x.jarを入れるとActionがSpringのDIコンテナで管理されるようになり、直接ServiceをDIできるようになる
Spring
生成
Struts XxxAction ServiceImpl
イベント
注入生成
最小構成の例(定義ファイル無し)
19
サンプル
・・・<html><body><s:property value="message"/></body></html>
・・・<html><body><s:property value="message"/></body></html>
hello.jsp
HelloAction
public class HelloAction {private String message; @Autowired private HelloService hello;public String getMessage() { return message; }public String execute() throws Exception {
message = hello.message();return "success";
}}
public class HelloAction {private String message; @Autowired private HelloService hello;public String getMessage() { return message; }public String execute() throws Exception {
message = hello.message();return "success";
}}
この例だと、struts.xmlは不要。Springの定義ファイルも
2行程度。本当にこれだけでOK!
20
合同会社Starlight&Storm (since 2008)• 最近のコンサル事例
– B2B ECサイト構築
• Seasar2, Teeda, DBFlute...– 基幹システム統合
• Spring, Flex/AIR, iBATIS...– 標準フレームワーク構築
• Spring, Velocity, SpringJDBC, iBATIS...– B2Bサイト構築
• Spring(WebFlow,Portlet,Batch...), ESB Mule...
• 教育コース– Spring2入門など
– 詳しくは「www.starlight-storm.com」をご参照ください
• お問い合わせ先– [email protected]
21
22
JSUG(日本Springユーザ会)
• 2006年7月に発足– 国内でのSpringに関する情報の発信や収集を目的に、活動
– http://springframework.jp/• 主な活動内容
– 勉強会• 2ヶ月1回程度(不定期開催)
– ML• 現在約600名• http://groups.google.co.jp/group/jsug