既にオワコンな気もするがプロジェクトで使う機会があったので書きとめておく。
BlazeDS とは
- アドビ社が2007年に公開したオープンソースプロジェクト。
- FlexやAdobe AIRのアプリケーションからサーバサイドのJavaオブジェクトをリモートで呼び出したり、サーバからのプッシュ配信を行う事ができるらしい。
- AMFというバイナリデータフォーマットを使用するので、JSONやXMLと比較してデータ転送量が小さいらしい。
- イマドキのナウなヤングが使っているWebSoketみたいなもの。
Spring BlazeDS Integration
- SpringとBlazeDSを連携するライブラリ。
- 最新バージョンは1.5.2(リリースは2011年)
- アノテーションをペコっと付けるだけでSpringコンテナ上のコンポーネントをリモートオブジェクトとして登録できる。
参考情報
-
Spring BlazeDS Integration のドキュメント(英語)
http://docs.spring.io/spring-flex/docs/1.0.x/reference/htmlsingle/spring-flex-reference.html -
Spring BlazeDS Integrationの解説記事
http://news.mynavi.jp/articles/2010/04/23/spring6/ -
上記記事のサンプルコード(springblazeds.zip)
http://news.mynavi.jp/articles/2010/04/23/spring6/resources/springblazeds.zip
既存 Spring MVC プロジェクトに Spring BlazeDS Integration を追加する方法
基本的には前述のサンプルコードを参考にすればできるのでポイントのみ記述する。
pom.xml
- Spring BlazeDS Integration の最新バージョン1.5だと BlazeDS 4 を使うらしいが、BlazeDS 4 はMaven リポジトリに登録されてないらしい。
- 色々と面倒なので1.0.3を使ったほうが楽。
<dependency>
<groupId>com.adobe.blazeds</groupId>
<artifactId>blazeds-core</artifactId>
<version>3.2.0.3978</version>
</dependency>
<dependency>
<groupId>com.adobe.blazeds</groupId>
<artifactId>blazeds-common</artifactId>
<version>3.2.0.3978</version>
</dependency>
<dependency>
<groupId>com.adobe.blazeds</groupId>
<artifactId>blazeds-opt</artifactId>
<version>3.2.0.3978</version>
</dependency>
<dependency>
<groupId>com.adobe.blazeds</groupId>
<artifactId>blazeds-proxy</artifactId>
<version>3.2.0.3978</version>
</dependency>
<dependency>
<groupId>com.adobe.blazeds</groupId>
<artifactId>blazeds-remoting</artifactId>
<version>3.2.0.3978</version>
</dependency>
<dependency>
<groupId>org.springframework.flex</groupId>
<artifactId>spring-flex</artifactId>
<version>1.0.3.RELEASE</version>
</dependency>
webmvc-config.xml
<mvc:annotation-driven>より前に<flex:message-broker>を記述する。
こうしないとBlazeDS側でリクエストが受け取れない。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:flex="http://www.springframework.org/schema/flex"
xsi:schemaLocation="http://www.springframework.org/schema/flex
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">
<flex:message-broker services-config-path="/WEB-INF/flex/services-config.xml">
<flex:mapping pattern="/messagebroker/*"/>
</flex:message-broker>
<mvc:annotation-driven>
service-config.xml
サンプルと同じ
リモートから呼び出すオブジェクト
クラスに@RemotingDestination、メソッドに@RemotingIncludeを付ける。
以下、Serviceクラスをリモートオブジェクトとして公開する場合。
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
@RemotingDestination
public class RemoteService {
@RemotingInclude
public List<RemoteObj> findAll() {
: