在學會了blazeds的簡單配置之后,今天嘗試了一下spring blazeds integration配置,被網上很多帖子坑了,比如這篇貌似不錯的:http://www.adobe.com/devnet/flex/articles/spring_blazeds_integration.html
按照這篇文章的方式配置,會得到錯誤:
[RPC Fault faultString="[MessagingError message='Destination 'XXXX' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']" faultCode="InvokeFailed" faultDetail="Couldn't establish a connection to 'userService'"]
在網上查原因,嘗試了3個多小時,才終于搞定,靠。
第一步: 下載blazeds的sample, https://www.adobe.com/cfusion/entitlement/index.cfm?e=lc_blazeds 下載那個40多M的turnkey,里面包含tomcat和sample application.
第二步:webapp目錄下有個blazeds目錄,這是做blazeds項目的一個基礎app, 新的app可以基于這個來做,lib目錄下已經包含相應的jar包了,一些configuration文件也都已經包括了??梢栽诋斍澳夸浽購椭普迟N出來一個副本,我命名為spring_blazeds。
第三步:改web.xml,內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>BlazeDS</display-name>
<description>BlazeDS Application</description>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/web-application-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
</web-app>
第四步:web-inf目錄下添加文件web-application-context.xml,內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:flex="http://www.springframework.org/schema/flex"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/flex
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">
<!-- Bootstraps and exposes the BlazeDS MessageBroker simplest form -->
<flex:message-broker/>
<bean id="productService" class="flex.samples.product.ProductService" >
<flex:remoting-destination />
</bean>
</beans>
第五步:
把web-inf/flex目錄下的services-config.xml的前幾行改成:
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<services>
<default-channels>
<channel ref="my-amf"/>
</default-channels>
</services>
這一步非常重要,我好幾個小時沒搞定問題,主要差的就是這一步!web-inf/flex目錄下的其他文件沒用,至少在這個例子里沒用。
第六步:
寫mxml文件:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="#FFFFFF">
<mx:RemoteObject id="srv" destination="productService"/>
<mx:DataGrid dataProvider="{srv.getProducts.lastResult}" width="100%" height="100%"/>
<mx:Button label="Get Data" click="srv.getProducts()"/>
</mx:Application>
第七步:
把turnkey里blazeds-turnkey-4.0.0.14931\tomcat\webapps\samples\WEB-INF\src\flex\samples\product目錄下的java文件編譯一下,放web-inf的classes目錄下。
第八步:
添加jar包,編譯mxml,把bin-debug目錄下的所有文件包括history目錄都拷貝到webroot下,我的是spring_blazeds。記得編譯時加選項
-services "C:\code\flex\blazeds-turnkey-4.0.0.14931\tomcat\webapps\spring_blazeds\WEB-INF\flex\services-config.xml" -locale en_US
所以你每次改services-config.xml都要重新編譯,替換webapp的文件。
然后運行應該就可以了!