人在江湖

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  82 Posts :: 10 Stories :: 169 Comments :: 0 Trackbacks
在学会了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文件也都已经包括了。可以在当前目录再复制粘贴出来一个副本,我命名为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的文件。

然后运行应该就可以了!
posted on 2013-06-07 15:08 人在江湖 阅读(1904) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: