2
2

More than 5 years have passed since last update.

BlazeDS を 既存 Spring MVC プロジェクトに導入する方法

Last updated at Posted at 2014-08-20

既にオワコンな気もするがプロジェクトで使う機会があったので書きとめておく。

BlazeDS とは

  • アドビ社が2007年に公開したオープンソースプロジェクト。
  • FlexやAdobe AIRのアプリケーションからサーバサイドのJavaオブジェクトをリモートで呼び出したり、サーバからのプッシュ配信を行う事ができるらしい。
  • AMFというバイナリデータフォーマットを使用するので、JSONやXMLと比較してデータ転送量が小さいらしい。
  • イマドキのナウなヤングが使っているWebSoketみたいなもの。

Spring BlazeDS Integration

  • SpringとBlazeDSを連携するライブラリ。
  • 最新バージョンは1.5.2(リリースは2011年)
  • アノテーションをペコっと付けるだけでSpringコンテナ上のコンポーネントをリモートオブジェクトとして登録できる。

参考情報

既存 Spring MVC プロジェクトに Spring BlazeDS Integration を追加する方法

基本的には前述のサンプルコードを参考にすればできるのでポイントのみ記述する。

pom.xml

  • Spring BlazeDS Integration の最新バージョン1.5だと BlazeDS 4 を使うらしいが、BlazeDS 4 はMaven リポジトリに登録されてないらしい。
  • 色々と面倒なので1.0.3を使ったほうが楽。
pom.xml
        <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側でリクエストが受け取れない。

webmvc-config.xml
<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クラスをリモートオブジェクトとして公開する場合。

RemoteService.java
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() {
    :
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2