• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

 Spring Rooの最もベーシックな使い方はroo shell上でentityコマンドを使ってEntityを作成していくやり方ですが、既にDB上にテーブルが存在していて、そのテーブルをEntityとして使用するアプリケーションを作ることもできます。

 Rooのインストール、プロジェクトの作成、DBの接続設定までは同様の手順で行います。

Spring Roo Install
[Spring Roo]プロジェクト作成, Logging&DB接続設定

 これ以降の手順は下記ページを参考に実施していきます。

Chapter 9. Incremental Database Reverse Engineering (DBRE) Add-On

 Database Reverse Engineering(DBRE)アドオンには database introspect と database reverse engineer の2つのコマンドがありますが、いずれかを初めて実行した場合にはJDBCドライバのインストールを促すプロンプトが表示されます。

   1  com.example roo> database introspect --schema no-schema-required
   2  Located add-ons that may offer this JDBC driver
   3  2 found, sorted by rank; T = trusted developer; R = Roo 1.1 compatible
   4  ID T R DESCRIPTION -------------------------------------------------------------
   5  01 - Y 9.0.0.801_jdbc4_0001 PostgreSQL #jdbcdriver...
   6  02 Y Y 9.0.801.0001 Postgres #jdbcdriver driverclass:org.postgresql.Driver....
   7  --------------------------------------------------------------------------------
   8  [HINT] use 'addon info id --searchResultId ..' to see details about a search result
   9  [HINT] use 'addon install id --searchResultId ..' to install a specific search result, or
  10  [HINT] use 'addon install bundle --bundleSymbolicName TAB' to install a specific add-on version
  11  JDBC driver not available for 'org.postgresql.Driver'

 ここで addon info コマンドを使うことで検出されたドライバの詳細情報を見ることが出来ます。

   1  com.example roo> addon info id --searchResultId 01
   2  Name.........: spring-roo-postgres-jdbc4-wrapper
   3  BSN..........: org.postgresql.roo.wrapper.postgresql
   4  Version......: 9.0.0.801_jdbc4_0001
   5  Roo Version..: 1.1
   6  Ranking......: 0.0
   7  JAR Size.....: 546943 bytes
   8  PGP Signature: 0x36673F56 signed by Ingo Thierack (ingothierack@googlemail.com)
   9  OBR URL......: http://spring-roo-postgres-jdbc4-wrapper.googlecode.com/svn/repo/
  10                 repository.xml
  11  JAR URL......: httppgp://spring-roo-postgres-jdbc4-wrapper.googlecode.com/svn/re
  12                 po/org/postgresql/roo/wrapper/org.postgresql.roo.wrapper.postgres
  13                 ql/9.0-801.jdbc4.0001/org.postgresql.roo.wrapper.postgresql-9.0-8
  14                 01.jdbc4.0001.jar
  15  Description..: PostgreSQL #jdbcdriver driverclass:org.postgresql.Driver. This
  16                 bundle wraps the standard Maven artifact:
  17                 postgresql-9.0-801.jdbc4.

 最新のドライバをインストールするために、下記コマンドを実行します。

   1  com.example roo> addon install id --searchResultId 01
   2  Download URL 'http://spring-roo-postgres-jdbc4-wrapper.googlecode.com/svn/repo/org/postgresql/roo/wrapper/org.postgresql
   3  .roo.wrapper.postgresql/9.0-801.jdbc4.0001/org.postgresql.roo.wrapper.postgresql-9.0-801.jdbc4.0001.jar' failed
   4  This resource was signed with PGP key ID '0x36673F56', which is not currently trusted
   5  Use 'pgp key view' to view this key, 'pgp trust' to trust it, or 'pgp automatic trust' to trust any keys
   6  Target resource(s):
   7  -------------------
   8     spring-roo-postgres-jdbc4-wrapper (9.0.0.801_jdbc4_0001)
   9  
  10  Deploying...done.
  11  
  12  Unable to install add-on: spring-roo-postgres-jdbc4-wrapper [version: 9.0.0.801_jdbc4_0001]

 おや、インストールに失敗してしまいました。どうやらドライバのダウンロードURLのKeyが信頼されていないということのようです。pgp key view コマンドを使用してkeyの情報を表示します。

   1  com.example roo> pgp key view --keyId 0x36673F56
   2  >>>> KEY ID: 0x36673F56 <<<<
   3       More Info: http://keyserver.ubuntu.com/pks/lookup?fingerprint=on&op=index&search=0x36673F56
   4       Created: 2011-1-30 18:36:08 +0000
   5       Fingerprint: dc1a2679fc6a938d6681a61389a2afd036673f56
   6       Algorithm: RSA_GENERAL
   7       User ID: Ingo Thierack <ingothierack@googlemail.com>
   8            Signed By: Key 0x36673F56 - not locally trusted
   9       Subkey ID: 0x1A2EDAED [RSA_GENERAL]

 このKeyを信頼してダウンロードを可能にするために、下記コマンドを実行します。

   1  com.example roo> pgp trust --keyId 0x36673F56
   2  Added trust for key:
   3  >>>> KEY ID: 0x36673F56 <<<<
   4       More Info: http://keyserver.ubuntu.com/pks/lookup?fingerprint=on&op=index&search=0x36673F56
   5       Created: 2011-1-30 18:36:08 +0000
   6       Fingerprint: dc1a2679fc6a938d6681a61389a2afd036673f56
   7       Algorithm: RSA_GENERAL
   8       User ID: Ingo Thierack <ingothierack@googlemail.com>
   9            Signed By: Key 0x36673F56 (Ingo Thierack <ingothierack@googlemail.com>)
  10       Subkey ID: 0x1A2EDAED [RSA_GENERAL]

 そして再度インストールコマンドを実行します。

   1  com.example roo> addon install id --searchResultId 01
   2  Target resource(s):
   3  -------------------
   4     spring-roo-postgres-jdbc4-wrapper (9.0.0.801_jdbc4_0001)
   5  
   6  Deploying...done.
   7  
   8  Successfully installed add-on: spring-roo-postgres-jdbc4-wrapper [version: 9.0.0.801_jdbc4_0001]
   9  [Hint] Please consider rating this add-on with the following command:
  10  [Hint] addon feedback bundle --bundleSymbolicName org.postgresql.roo.wrapper.postgresql --rating ... --comment "..."

 無事にインストールできました。次にDBREアドオンのdatabase introspectコマンドでテーブルの情報を表示します。

   1  com.example roo> database introspect --schema public --file --enableViews

 出力内容は割愛しますが、XML形式でスキーマの情報が表示されます。

 そして実際にテーブル情報からEntityを作成するためにdatabase reverse engineerコマンドを実行します。

   1  com.example roo> database reverse engineer --schema public --package ~.domain --testAutomatically
   2  Created SRC_MAIN_RESOURCES\dbre.xml
   3  Updated ROOT\pom.xml
   4  Updated SRC_MAIN_RESOURCES\META-INF\persistence.xml
   5  Created SRC_MAIN_JAVA\com\example\domain
   6  Created SRC_MAIN_JAVA\com\example\domain\Access.java
   7  Created SRC_MAIN_JAVA\com\example\domain\Content.java
   8  Created SRC_TEST_JAVA\com\example\domain
   9  Created SRC_TEST_JAVA\com\example\domain\AccessDataOnDemand.java
  10  Created SRC_TEST_JAVA\com\example\domain\AccessIntegrationTest.java
  11  Created SRC_TEST_JAVA\com\example\domain\ContentDataOnDemand.java
  12  Created SRC_TEST_JAVA\com\example\domain\ContentIntegrationTest.java
  13  Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_Configurable.aj
  14  Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_Entity.aj
  15  Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_DbManaged.aj
  16  Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_ToString.aj
  17  Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_Configurable.aj
  18  Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_Entity.aj
  19  Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_DbManaged.aj
  20  Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_ToString.aj
  21  Created SRC_TEST_JAVA\com\example\domain\AccessDataOnDemand_Roo_Configurable.aj
  22  Created SRC_TEST_JAVA\com\example\domain\ContentDataOnDemand_Roo_DataOnDemand.aj
  23  Created SRC_TEST_JAVA\com\example\domain\AccessDataOnDemand_Roo_DataOnDemand.aj
  24  Created SRC_TEST_JAVA\com\example\domain\ContentIntegrationTest_Roo_Configurable.aj
  25  Created SRC_TEST_JAVA\com\example\domain\ContentIntegrationTest_Roo_IntegrationTest.aj
  26  Created SRC_TEST_JAVA\com\example\domain\ContentDataOnDemand_Roo_Configurable.aj
  27  Created SRC_TEST_JAVA\com\example\domain\AccessIntegrationTest_Roo_Configurable.aj
  28  Created SRC_TEST_JAVA\com\example\domain\AccessIntegrationTest_Roo_IntegrationTest.aj

 --schemaオプションで対象のDBスキーマを、--packageオプションでEntityを作成するパッケージを指定します。--testAutomaticallyを指定することでEntityのインテグレーションテストが自動的に作成されます。

 また、--excludeTablesオプションや--includeTablesオプションで対象のテーブルを特定のテーブルに限定することも出来ます。

 これ以降の手順は、roo shellからEntityを作成したあとと同じ手順でWebアプリケーションのセットアップなどを行うことが出来ます。

posted by Png akanuma on Tue 20 Dec 2011 at 08:34

 Cloud Foundryに申し込んで使えるようになったので、Spring Roo in Actionの11章を参考にRooのアプリケーションをデプロイしてみました。

 まずはroo shellからCloud Foundryを走査するためのAddonをインストールします。インストールの間自動的に認証されるよう、下記コマンドを実行します。

   1  roo> pgp automatic trust
   2  Automatic PGP key trusting enabled (this is potentially unsafe); disable by typing 'pgp automatic trust' again

そして下記コマンドでAddonをインストールします。

   1  roo> addon install bundle --bundleSymbolicName org.springframework.roo.addon.cloud.foundry;1.1.5.RELEASE
   2  Target resource(s):
   3  -------------------
   4     Spring Roo - Addon - Cloud Foundry (1.1.5.RELEASE)
   5  
   6  Required resource(s):
   7  ---------------------
   8     Spring Beans (3.0.5.RELEASE)
   9     jcl-over-slf4j (1.6.1)
  10     slf4j-nop (1.6.1)
  11     Spring AOP (3.0.5.RELEASE)
  12     Servlet Specification API (2.5.0)
  13     Spring Core (3.0.5.RELEASE)
  14     Jackson JSON processor (1.6.2)
  15     Data mapper for Jackson JSON processor (1.6.2)
  16     Spring Context (3.0.5.RELEASE)
  17     Spring Roo - Wrapping - aopalliance (1.0.0.0010)
  18     Spring Web (3.0.5.RELEASE)
  19     slf4j-api (1.6.1)
  20     Spring Roo - Wrapping - Cloud Foundry API (0.0.1.0010)
  21  
  22  Optional resource(s):
  23  ---------------------
  24     Spring Expression Language (3.0.5.RELEASE)
  25     Spring ASM (3.0.5.RELEASE)
  26  
  27  Deploying...done.
  28  
  29  Successfully installed add-on: Spring Roo - Addon - Cloud Foundry [version: 1.1.5.RELEASE]
  30  [Hint] Please consider rating this add-on with the following command:
  31  [Hint] addon feedback bundle --bundleSymbolicName org.springframework.roo.addon.cloud.foundry --rating ... --comment "..
  32  ."

Roo in Actionの例では "addon install bundle --bundleSymbolicName org.springframework.roo.addon.cloud.foundry" という感じにバージョン番号を指定していないのですが、これだと最新のバージョンがインストールされます。今回のケースではSpring Rooのバージョンが1.1.5なので、Addonのインストールでもバージョンを1.1.5に指定しないとこの時点の最新である1.2.0.RC1がインストールされてしまい、うまくいきません。

インストールが終了したら自動認証をOFFに戻します。

   1  roo> pgp automatic trust
   2  Automatic PGP key trusting disabled (this is the safest option)

Addonをインストールしたことでcloud foundryコマンドが使用できるようになっています。まずはCloud Foundryにログインします。

   1  roo> cloud foundry login --email xxxxxxxxxx@xxxxx.xxx --password xxxxxxxxxx
   2  Credentials saved.
   3  Logged in successfully with email address 'xxxxxxxxxx@xxxxx.xxx'

Cloud Foundryの環境についての情報を表示するには下記コマンドを実行します。

   1  roo> cloud foundry info
   2  
   3  
   4  VMware's Cloud Application Platform
   5  For support visit http://support.cloudfoundry.com
   6  
   7  
   8  Target:     http://api.cloudfoundry.com (0.999)
   9  
  10  
  11  User:     hiroaki.akanuma@gmail.com
  12  Usage:     Memory (128MB of 2048MB total)
  13       Services (0 of 16 total)
  14       Apps (1 of 20 total)

現在デプロイされているアプリケーションのリストは下記コマンドで確認できます。

   1  roo> cloud foundry list apps
   2  
   3  =================================== Applications ===================================
   4  
   5  Name             Status      Instances     Services     URLs
   6  ----             ------      ---------     --------     ----
   7  akanumahello     STARTED     1                          akanumahello.cloudfoundry.com

上記の出力では akanumahello というアプリケーションがすでにデプロイされていることが分かります。

また、現在使用可能なサービスのリストは下記コマンドで確認できます。

   1  roo> cloud foundry list services
   2  
   3  ======================= System Services ========================
   4  
   5  Service        Version     Description
   6  -------        -------     -----------
   7  mysql          5.1         MySQL database service
   8  postgresql     9.0         PostgreSQL database service (vFabric)
   9  mongodb        1.8         MongoDB NoSQL store
  10  redis          2.2         Redis key-value store service
  11  rabbitmq       2.4         RabbitMQ messaging service
  12  
  13  
  14  There are currently no provisioned services.

ではアプリケーションをデプロイしてみます。cloud foundry deploy コマンドでデプロイすることができます。

   1  roo> cloud foundry deploy --appName cftest --path CREATE
   2  ~~中略~~
   3  Operation could not be completed: 400 Bad Request

上記のように 400 Bad Request となってしまった場合は、--appName で指定したアプリケーション名がすでに使われているということなので、アプリケーション名を変更して再度デプロイします。

   1  roo> cloud foundry deploy --appName cftestaka --path CREATE
   2  ~~中略~~
   3  The application 'cftestaka' was successfully pushed

上記のように successfully pushed と出力されればデプロイ成功です。アプリケーションの一覧を確認してみます。

   1  roo> cloud foundry list apps
   2  
   3  =================================== Applications ===================================
   4  
   5  Name             Status      Instances     Services     URLs
   6  ----             ------      ---------     --------     ----
   7  akanumahello     STARTED     1                          akanumahello.cloudfoundry.com
   8  cftestaka        STOPPED     1                          cftestaka.cloudfoundry.com

cftestakaというアプリケーションが一覧に追加されています。StatusがSTOPPEDになっていてまだ起動はしていないので、下記コマンドでアプリケーションを起動します。

   1  roo> cloud foundry start app --appName cftestaka
   2  The application 'cftestaka' was successfully started
   3  roo> cloud foundry list apps
   4  
   5  =================================== Applications ===================================
   6  
   7  Name             Status      Instances     Services     URLs
   8  ----             ------      ---------     --------     ----
   9  akanumahello     STARTED     1                          akanumahello.cloudfoundry.com
  10  cftestaka        STARTED     1                          cftestaka.cloudfoundry.com

Status が STARTED に変わり、アプリケーションが起動されました。http://cftestaka.cloudfoundry.com/ にアクセスしてトップページが表示されれば起動に成功しています。

稼働中のアプリケーションの統計情報については下記コマンドで確認できます。

   1  roo> cloud foundry view app stats --appName cftestaka
   2  
   3  ============================== App. Stats ==============================
   4  
   5  Instance     CPU (Cores)     Memory (limit)     Disk (limit)      Uptime
   6  --------     -----------     --------------     ------------      ------
   7  0            8.0 (4)         239.09M (256M)     28.0M (2048M)     0d:

さて、アプリケーションは起動しましたが、まだDBが使えるようになっていないので、Entityを操作するための画面に遷移しようとするとエラーになってしまいます。

まずはDBをサービスとして作成します。

   1  roo> cloud foundry create service --serviceName cftesakadb --serviceType postgresql
   2  The service 'cftesakadb' was successfully created

サービスの一覧を確認すると、= Provisioned Services = の部分にサービスが追加になっています。

   1  roo> cloud foundry list services
   2  
   3  ======================= System Services ========================
   4  
   5  Service        Version     Description
   6  -------        -------     -----------
   7  mysql          5.1         MySQL database service
   8  postgresql     9.0         PostgreSQL database service (vFabric)
   9  mongodb        1.8         MongoDB NoSQL store
  10  redis          2.2         Redis key-value store service
  11  rabbitmq       2.4         RabbitMQ messaging service
  12  
  13  
  14  
  15  = Provisioned Services =
  16  
  17  Name           Service
  18  ----           -------
  19  cftesakadb     postgresql

次に、作成したサービスをアプリケーションに紐付けます。

   1  roo> cloud foundry bind service --serviceName cftesakadb --appName cftestaka
   2  The service 'cftesakadb' was successfully bound to the application 'cftestaka'
   3  roo>

そしてアプリケーションを再起動します。

   1  roo> cloud foundry restart app --appName cftestaka
   2  The application 'cftestaka' was successfully restarted

これでアプリケーションがDBを使えるようになり、EntityのCRUD画面も動作するようになります。

アプリケーションのログを確認するには下記コマンドを実行します。

   1  roo> cloud foundry view logs --appName cftestaka --instance 0

長いので出力は省略しますが、stderr.logとstdout.logが閲覧できます。

それと現在のメモリの割当量は下記コマンドで確認できます。

   1  roo> cloud foundry view app memory --appName cftestaka
   2  
   3  = Application Memory =
   4  
   5  Name          Memory
   6  ----          ------
   7  cftestaka     256MB

現在は256MBのメモリが割り当てられています。この割当量を変更するには下記のようにコマンドを実行します。

   1  roo> cloud foundry update app memory --appName cftestaka --memSize 512MB
   2  
   3  = Application Memory =
   4  
   5  Name          Memory
   6  ----          ------
   7  cftestaka     512MB

メモリ量が512MBに変更されました。

RooとCloud Foundryの組み合わせなら簡単なCRUDアプリの公開はとてもスピーディーに行うことができそうです。まだCloud Foundryはベータ版なので、正式版になったときに料金体系などがどうなるかは気になりますが、Roo + Cloud Foundryで何か公開できるようなサービスでも作れないかなぁと思っています。

posted by Png akanuma on Mon 12 Dec 2011 at 00:01

 名前は聞いたことがあったもののどんなものかよく分かってなかったので、下記チュートリアルページを参考にCloud Foundryを触ってみました。

VMware Cloud Foundry入門 - Getting Started (Japanese)

 Cloud FoundryはVMwareが提供しているオープンソースのPaaSフレームワークで、ソースコードを取得してPaaS環境を構築できるほか、VMwareがvSphereデータセンター内で運営しているCloud Foundryのホステッド環境に接続することができます。現在はβ版ということで、無料で利用できるようです。

 まずは http://www.cloudfoundry.com/ でメールアドレスを登録してサインアップ。すぐに「Welcome to Cloud Foundry」という件名のメールが届きますが、これは登録を受け付けたというだけで、実際にアカウントが用意されて使用可能になるのはしばらくして「Welcome to Cloud Foundry - Your signup is approved!」という件名のメールでパスワードが届いてからになります。私の場合は2日ほどで届きました。

 とりあえず自宅PCのWindows環境で試してみました。まず http://www.rubyinstaller.org/ から rubyinstaller-1.9.3-p0.exe をダウンロードしてRubyをインストールします。

   1  C:\Users\akanuma>ruby -version
   2  ruby 1.9.3p0 (2011-10-30) [i386-mingw32]
   3  -e:1:in `<main>': undefined local variable or method `rsion' for main:Object (NameError)

なにやらエラーが出ていますが、とりあえず続行。

Cloud FoundryのCLIであるvmcをインストールします。

   1  C:\Users\akanuma>gem install vmc
   2  Fetching: spruz-0.2.13.gem (100%)
   3  Fetching: json_pure-1.5.4.gem (100%)
   4  Fetching: rubyzip2-2.0.1.gem (100%)
   5  Fetching: mime-types-1.17.2.gem (100%)
   6  Fetching: rest-client-1.6.7.gem (100%)
   7  Fetching: terminal-table-1.4.4.gem (100%)
   8  Fetching: interact-0.2.gem (100%)
   9  Fetching: vmc-0.3.13.gem (100%)
  10  Successfully installed spruz-0.2.13
  11  Successfully installed json_pure-1.5.4
  12  Successfully installed rubyzip2-2.0.1
  13  Successfully installed mime-types-1.17.2
  14  Successfully installed rest-client-1.6.7
  15  Successfully installed terminal-table-1.4.4
  16  Successfully installed interact-0.2
  17  Successfully installed vmc-0.3.13
  18  8 gems installed
  19  Installing ri documentation for spruz-0.2.13...
  20  Installing ri documentation for json_pure-1.5.4...
  21  Installing ri documentation for rubyzip2-2.0.1...
  22  Installing ri documentation for mime-types-1.17.2...
  23  Installing ri documentation for rest-client-1.6.7...
  24  unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for README.rdoc, skipping
  25  Installing ri documentation for terminal-table-1.4.4...
  26  Installing ri documentation for interact-0.2...
  27  Installing ri documentation for vmc-0.3.13...
  28  Installing RDoc documentation for spruz-0.2.13...
  29  Installing RDoc documentation for json_pure-1.5.4...
  30  Installing RDoc documentation for rubyzip2-2.0.1...
  31  Installing RDoc documentation for mime-types-1.17.2...
  32  Installing RDoc documentation for rest-client-1.6.7...
  33  unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for README.rdoc, skipping
  34  Installing RDoc documentation for terminal-table-1.4.4...
  35  Installing RDoc documentation for interact-0.2...
  36  Installing RDoc documentation for vmc-0.3.13...

vmcのtargetコマンドでデプロイ対象を api.cloudfoundry.com に設定します。

   1  C:\Users\akanuma>vmc target api.cloudfoundry.com
   2  Succesfully targeted to [http://api.cloudfoundry.com]

続けてログインコマンドを実行します。

   1  C:\Users\akanuma>vmc login
   2  Email: xxxxxxxxxx@xxxxx.xxx
   3  Password: ********
   4  Successfully logged into [http://api.cloudfoundry.com]

そしてアプリケーションを作成するためのディレクトリを作成して移動します。

   1  C:\Users\akanuma>mkdir hello
   2  C:\Users\akanuma>cd hello
   3  C:\Users\akanuma\hello>

次にhllo.rbという名前で下記内容のファイルを作成します。文字コードはUTF-8で、改行コードはLFにしないと失敗するようです。

   1  require 'sinatra'
   2  get '/' do
   3    "Hello from Cloud Foundry!"
   4  end

アプリケーションをデプロイします。vmc pushコマンドを実行すると追加の情報入力用のプロンプトが表示されますので、それぞれ下記のように入力します。

   1  C:\Users\akanuma\hello>vmc push
   2  Would you like to deploy from the current directory? [Yn]:
   3  Application Name: akanumahello
   4  Application Deployed URL ["akanumahello.cloudfoundry.com"]:
   5  Detected a Sinatra Application, is this correct? [Yn]:
   6  Memory Reservation ("64M", "128M", "256M", "512M", "1G", "2G") ["128M"]:
   7  Creating Application: OK
   8  Would you like to bind any services to 'akanumahello'? [yN]:
   9  Uploading Application:
  10    Checking for available resources: OK
  11    Packing application: OK
  12    Uploading (0K): OK
  13  Push Status: OK
  14  Staging Application: OK
  15  Starting Application: OK

無事デプロイされたようです。ブラウザで http://akanumahello.cloudfoundry.com/ にアクセスして「Hello from Cloud Foundry!」と表示されればひとまず成功です。

続けて変更を加えてみます。hello.rbの "Hello from Cloud Foundry!" を "Hello from Cloud Foundry and VMware!" に変更して保存します。そして下記コマンドでサーバ上に変更を反映します。

   1  C:\Users\akanuma\hello>vmc update akanumahello
   2  Uploading Application:
   3    Checking for available resources: OK
   4    Packing application: OK
   5    Uploading (0K): OK
   6  Push Status: OK
   7  Stopping Application: OK
   8  Staging Application: OK
   9  Starting Application: OK

ブラウザで再度表示を確認して、変更が反映されていれば成功です。

このチュートリアルを試す限りは簡単にアプリケーションを公開できそうです。メモリも2GBまでは使えるようですので、あまり負荷の高くないアプリケーションであれば十分に使えそうです。

posted by Png akanuma on Sun 11 Dec 2011 at 18:57

 前回まででEntityの作成まで終わったので、Webアプリケーションとして動作させるためのメモです。

以前のエントリはこちら
Spring Roo Install
[Spring Roo]プロジェクト作成, Logging&DB接続設定
[Spring Roo]Entity作成

・roo shell上でwebコマンドを実行することで、Webアプリケーションとして動作するために必要なファイルが生成されます。

   1  roo> web mvc setup
   2  Created SRC_MAIN_WEBAPP\WEB-INF\spring
   3  Created SRC_MAIN_WEBAPP\WEB-INF\spring\webmvc-config.xml
   4  Created SRC_MAIN_WEBAPP\WEB-INF\web.xml
   5  Updated SRC_MAIN_WEBAPP\WEB-INF\spring\webmvc-config.xml
   6  Created SRC_MAIN_WEBAPP\images
   7  Created SRC_MAIN_WEBAPP\images\create.png
   8  Created SRC_MAIN_WEBAPP\images\list.png
   9  Created SRC_MAIN_WEBAPP\images\resultset_previous.png
  10  Created SRC_MAIN_WEBAPP\images\resultset_next.png
  11  Created SRC_MAIN_WEBAPP\images\show.png
  12  Created SRC_MAIN_WEBAPP\images\favicon.ico
  13  Created SRC_MAIN_WEBAPP\images\delete.png
  14  Created SRC_MAIN_WEBAPP\images\resultset_first.png
  15  Created SRC_MAIN_WEBAPP\images\springsource-logo.png
  16  Created SRC_MAIN_WEBAPP\images\resultset_last.png
  17  Created SRC_MAIN_WEBAPP\images\add.png
  18  Created SRC_MAIN_WEBAPP\images\banner-graphic.png
  19  Created SRC_MAIN_WEBAPP\images\update.png
  20  Created SRC_MAIN_WEBAPP\styles
  21  Created SRC_MAIN_WEBAPP\styles\alt.css
  22  Created SRC_MAIN_WEBAPP\styles\standard.css
  23  Created SRC_MAIN_WEBAPP\WEB-INF\classes
  24  Created SRC_MAIN_WEBAPP\WEB-INF\classes\standard.properties
  25  Created SRC_MAIN_WEBAPP\WEB-INF\classes\alt.properties
  26  Created SRC_MAIN_WEBAPP\WEB-INF\layouts
  27  Created SRC_MAIN_WEBAPP\WEB-INF\layouts\default.jspx
  28  Created SRC_MAIN_WEBAPP\WEB-INF\layouts\layouts.xml
  29  Created SRC_MAIN_WEBAPP\WEB-INF\views
  30  Created SRC_MAIN_WEBAPP\WEB-INF\views\header.jspx
  31  Created SRC_MAIN_WEBAPP\WEB-INF\views\footer.jspx
  32  Created SRC_MAIN_WEBAPP\WEB-INF\views\views.xml
  33  Created SRC_MAIN_WEBAPP\WEB-INF\views\index.jspx
  34  Created SRC_MAIN_WEBAPP\WEB-INF\views\index-template.jspx
  35  Created SRC_MAIN_WEBAPP\WEB-INF\views\uncaughtException.jspx
  36  Created SRC_MAIN_WEBAPP\WEB-INF\views\resourceNotFound.jspx
  37  Created SRC_MAIN_WEBAPP\WEB-INF\views\dataAccessFailure.jspx
  38  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form
  39  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\update.tagx
  40  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\create.tagx
  41  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\dependency.tagx
  42  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\show.tagx
  43  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\list.tagx
  44  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\find.tagx
  45  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields
  46  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\select.tagx
  47  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\display.tagx
  48  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\column.tagx
  49  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\editor.tagx
  50  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\checkbox.tagx
  51  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\simple.tagx
  52  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\input.tagx
  53  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\textarea.tagx
  54  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\datetime.tagx
  55  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\table.tagx
  56  Created SRC_MAIN_WEBAPP\WEB-INF\tags\form\fields\reference.tagx
  57  Created SRC_MAIN_WEBAPP\WEB-INF\tags\menu
  58  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util
  59  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\pagination.tagx
  60  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\theme.tagx
  61  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\placeholder.tagx
  62  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\panel.tagx
  63  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\language.tagx
  64  Created SRC_MAIN_WEBAPP\WEB-INF\tags\util\load-scripts.tagx
  65  Created SRC_MAIN_WEBAPP\WEB-INF\i18n
  66  Created SRC_MAIN_WEBAPP\WEB-INF\i18n\messages.properties
  67  Created SRC_MAIN_WEBAPP\images\en.png
  68  Updated SRC_MAIN_WEBAPP\WEB-INF\i18n\application.properties
  69  Updated SRC_MAIN_WEBAPP\WEB-INF\web.xml
  70  Updated ROOT\pom.xml [added dependencies org.springframework:spring-web:${spring.version}, org.springframework:spring-we
  71  bmvc:${spring.version}, org.springframework.webflow:spring-js-resources:2.2.1.RELEASE, commons-digester:commons-digester
  72  :2.0, commons-fileupload:commons-fileupload:1.2.1, javax.servlet.jsp.jstl:jstl-api:1.2, org.glassfish.web:jstl-impl:1.2,
  73  javax.el:el-api:1.0, joda-time:joda-time:1.6, javax.servlet.jsp:jsp-api:2.1, commons-codec:commons-codec:1.4; updated p
  74  roject type to war; added dependencies org.apache.tiles:tiles-core:2.2.1, org.apache.tiles:tiles-jsp:2.2.1]
  75  Updated SRC_MAIN_WEBAPP\WEB-INF\views\footer.jspx

  • Webアプリケーションに必要なweb.xmlなどのファイルが生成されました。

  • また、Rooで作成されるのはSpringMVCアプリケーションですので、webmvc-config.xmlなどのSpringMVCのファイルも生成されます。

  • さらにデフォルトの画面を表示するためのファイルも生成されています。Rooで生成されるSpringMVCアプリケーションでは画面表示にtilesとjspxを使用しているため、デフォルト画面や共通のヘッダ、フッタ用のjspxファイルやtagxファイルが生成されました。CSSや画像ファイルも生成されます。

  • 次に各EntityのControllerを作成していきます。Project EntityのControllerを作成するには下記のようにcontroller scaffoldコマンドを実行します。

   1  roo> controller scaffold --class ~.web.ProjectController --entity ~.model.Project
   2  Created SRC_MAIN_JAVA\com\example\web
   3  Created SRC_MAIN_JAVA\com\example\web\ProjectController.java
   4  Updated SRC_MAIN_WEBAPP\WEB-INF\spring\webmvc-config.xml
   5  Created SRC_MAIN_JAVA\com\example\web\ApplicationConversionServiceFactoryBean.java
   6  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects
   7  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects\views.xml
   8  Updated SRC_MAIN_WEBAPP\WEB-INF\views\projects\views.xml
   9  Created SRC_MAIN_WEBAPP\WEB-INF\views\menu.jspx
  10  Created SRC_MAIN_WEBAPP\WEB-INF\tags\menu\menu.tagx
  11  Created SRC_MAIN_WEBAPP\WEB-INF\tags\menu\item.tagx
  12  Created SRC_MAIN_WEBAPP\WEB-INF\tags\menu\category.tagx
  13  Updated SRC_MAIN_WEBAPP\WEB-INF\views\menu.jspx
  14  Updated SRC_MAIN_WEBAPP\WEB-INF\views\projects\views.xml
  15  Updated SRC_MAIN_WEBAPP\WEB-INF\views\menu.jspx
  16  Updated SRC_MAIN_WEBAPP\WEB-INF\i18n\application.properties
  17  Created SRC_MAIN_JAVA\com\example\web\ProjectController_Roo_Controller.aj
  18  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects\list.jspx
  19  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects\show.jspx
  20  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects\create.jspx
  21  Created SRC_MAIN_WEBAPP\WEB-INF\views\projects\update.jspx
  22  Created SRC_MAIN_JAVA\com\exampler\web\ApplicationConversionServiceFactoryBean_Roo_ConversionService.aj

  • --classオプションでControllerクラス名を指定し、--entityオプションで対象になるEntityを指定します。上記の例ではProjectControllerという名前のControllerクラスが作成されました。また、Project Entityに対するCRUD画面表示用のjspxファイルや、tilesの設定ファイルも生成されています。

  • これだけでProject Entityに対する一覧表示、詳細表示、作成、更新、削除の画面・機能が一通り提供されてしまいます。

  • 同様に各Entityに対してControllerを生成します。

  • これでWebアプリケーションとして動作するようになりましたので、コマンドプロンプトからmvnコマンドを実行してアプリケーションを起動します。(roo shellではなくコマンドプロンプトです。)

   1  >mvn jetty:run

  • Webブラウザから下記のURLでアクセスすることが出来ます。

   1  http://localhost:8080/example

  • 画面左側のメニューから各Entityの操作が可能になっています。
posted by Png akanuma on Thu 1 Dec 2011 at 08:27
Contents
[Spring Roo]DBからのReverse Engineering
[Spring Roo]Cloud Foundryにアプリをデプロイ
Cloud Foundryを触ってみました
[Spring Roo]Webアプリケーションセットアップ
Comments
yoku0825: nkfの方が使いやすいですが、glibcに含まれているiconvの方が 確実にどの環境にも入っ... '12-6
Hiroaki Akanuma: ご指摘ありがとうございます。「嗜好度は大きい値がより嗜好度が強いことを意味すればどのような値で... '11-11
akr: 初めての推薦エンジンのところ 「属性データはどんなものでも可能。」 は preference ... '11-11
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ