Spring Boot + Spring Integration でいろいろ試してみる ( その7 )( STS の integration-graph で Spring Integration のフロー図を描く )
概要
記事一覧はこちらです。
Spring Boot + Spring Integration でいろいろ試してみる ( その4 )( 監視しているディレクトリに置かれた Excel ファイルのデータを DB に登録する → 処理が終わったら Excel ファイルを削除/移動する ) で STS の integration-graph を利用して Spring Integration のフロー図を描いたので、忘れない内に手順を残しておきます。
参照したサイト・書籍
目次
- STS をダウンロードする
- ダウンロードした zip ファイルを解凍する
- STS を起動する
- Spring Project を作成する
- Spring Integration の XML ファイルを作成し、integration-graph を表示する
- filter と excelToDbChannel を追加してみる
手順
STS をダウンロードする
Spring Tool Suite の Web ページにアクセスし、画面右側の「DOWNLOAD STS」ボタンをクリックして spring-tool-suite-3.8.1.RELEASE-e4.6-win32-x86_64.zip をダウンロードします。
ダウンロードした zip ファイルを解凍する
spring-tool-suite-3.8.1.RELEASE-e4.6-win32-x86_64.zip を解凍します。この時、解凍ツールの「フォルダを作成して解凍」のような機能は使用せず単に解凍します。zip ファイル名が長過ぎるので「フォルダを作成して解凍」のような機能を使うと解凍できません。
解凍すると sts-bundle というフォルダが作成されますので、C:\ 直下に移動します。
STS を起動する
C:\sts-bundle\sts-3.8.1.RELEASE の下に STS.exe というファイルがありますので、ダブルクリックして起動します。
「Select a directory as workspace」というタイトルの Eclipse Launcher ダイアログが表示されますので、Workspace のパスを C:\sts-bundle\workspace に変更した後「OK」ボタンをクリックします。
起動すると以下の画面が表示されます。
Spring Project を作成する
メインメニューから「File」-「New」-「Spring Starter Project」を選択します。
「New Spring Starter Project」ダイアログが表示されます。何も変更せずに「Next」ボタンをクリックします。
次の画面が表示されます。Boot Version を「1.3.7」に変更し、「I/O」グループの中の「Integration」をチェックした後「Finish」ボタンをクリックします。
「Import Getting Started Content」ダイアログが表示されますので終了するまで待ちます。
「Import Getting Started Content」ダイアログが閉じてメイン画面に戻ると「Package Explorer」に demo プロジェクトが表示されます。
Spring Integration の XML ファイルを作成し、integration-graph を表示する
作成した demo プロジェクトの src/main/resources の下に以下の内容の integration.xml というファイルを作成します。
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration" xmlns:file="http://www.springframework.org/schema/integration/file" xmlns:feed="http://www.springframework.org/schema/integration/feed" xsi:schemaLocation="http://www.springframework.org/schema/integration/feed http://www.springframework.org/schema/integration/feed/spring-integration-feed.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"> <int:inbound-channel-adapter channel="inChannel" ref="InDirChecker" method="checkFile" id="checkFile"> </int:inbound-channel-adapter> <int:channel id="inChannel"></int:channel> <int:service-activator ref="FileProcessor" method="process" id="process" input-channel="inChannel"> </int:service-activator> </beans>
作成したら integration.xml をダブルクリックしてソースを表示します。
integration.xml の内容が表示されたら、そのウィンドウの下に「integraion-graph」タブがあります。それをクリックすると integraion-graph が表示されます。
filter と excelToDbChannel を追加してみる
まず integration.xml タブをダブルクリックして、ウィンドウ内全画面表示にします。
画面左側の「Channels」の中の「channel」アイコンを Drag&Drop します。
Drag&Drop した channel アイコンをダブルクリックすると Properties ウィンドウが表示されるので、id に
excelToDbChannel
と入力します。画面左側の「Routing」の中の「filter」アイコンを Drag&Drop します。
Drag&Drop した filter アイコンをダブルクリックして Properties ウィンドウを表示した後、id に
filter
と入力します。画面右側の「connection」アイコンを選択した後、「inChannel」アイコンをクリック→「filter」アイコンをクリックして接続します。
次に「filter」アイコンをクリック→「excelToDbChannel」アイコンをクリックして接続します。
最後に「excelToDbChannel」アイコンをクリック→「process」アイコンをクリックして接続します。
作成したフロー図を画像ファイルに保存したい場合には、メインメニューから「File」-「Export…」を選択します。
「Save As」ダイアログが表示されます。「File name」のファイル名が最初は “graph.jpg” と表示されますので、"graph.png" に変更して「OK」ボタンをクリックします。拡張子を “.png” に変更すれば PNG 画像として保存されます。
履歴
2016/09/12
初版発行。