1. grails create-app myproject (創建名為myproject的grails應用工程)
2. grails install-plugin flex (安裝grails的flex插件,首次安裝的話會比較慢,因為會下載很多Flex和BlazeDS的jar文件)
3. grails create-service Hello (生成一個HelloService.groovy, 在grails-app/services目錄下), 編輯該文件:
1. class HelloService {
2.
3. static expose = ['flex-remoting']
4.
5. boolean transactional = true
6.
7. def hello() {
8. return "Hello,world!"
9. }
10.
11. }
4. 編寫flex客戶端, 比如main.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:RemoteObject id="ro" destination="helloService"/>
<mx:Button label="Hello" click="ro.hello()"/> <mx:TextInput text="{ro.hello.lastResult}"/>
</mx:Application>
5. 使用grails run-app 啟動服務器
6. 訪問http://localhost:8080/sample/bin/sample.mxml,或者http://localhost:8080/sample/bin/sample.html
點擊“Hello”,就可以顯示Hello world了
注意:如果無法訪問編譯sample.mxml生成的sample.html,則需要指定兩個參數
1) 指定-services參數為web-app/WEB-INF/flex/services-config.xml(相對或絕對路徑都可),
2) 指定-context-root參數為web的context,如本例中為sample