Flex 的spring+BlazeDS整合注意事项

弄了一天,终于把spring+BlazeDS整合好了。
首先阅读了:spring的官方文档【Spring BlazeDS Integration Reference Guide】。
[url]http://static.springsource.org/spring-flex/docs/1.0.x/reference/html/index.html[/url]
好多页,慢慢看。
但是按照整个文档,一步一步走下来,还是不行,经过多次尝试,终于可以了,现在把心得写下来,仅供参考。
本来我的j2ee工程是 extjs+spring2.56+hibernate3.3的,因为需要就整合flex,这时就需要BlazeDS了,
需要下:org.springframework.flex-1.0.0.RELEASE.jar。
还有flex需要 /WEB-INF/flex/整个目录。

注意点:
1,写spring blazeds配置文件:spring-context-80-BlazeDS.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-2.5.xsd
http://www.springframework.org/schema/flex
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">
<!-- Bootstraps and exposes the BlazeDS MessageBroker -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/messagebroker/*=_messageBroker
</value>
</property>
</bean>

<!-- Dispatches requests mapped to a MessageBroker -->
<bean class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter"/>

<!-- Bootstraps and exposes the BlazeDS MessageBroker -->
<bean id="_messageBroker" class="org.springframework.flex.core.MessageBrokerFactoryBean" /><bean id="flex_base_service" class="com.ria.conn.amf.service.impl.FlexBaseService"/>
<bean id="flex_base_service_000" class="org.springframework.flex.remoting.RemotingDestinationExporter">
<property name="messageBroker" ref="_messageBroker"/>
<property name="service" ref="flex_base_service"/>

<property name="channels">
<list>
<value>my-amf</value>
<value>my-secure-amf</value>
<value>my-polling-amf</value>
<value>my-streaming-amf</value>
</list>
</property>
</bean>
</beans>

2,web.xml里面 修改url的拦截器为spring.

<servlet>
<servlet-name>SpringMVCDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/applicationContext*.xml
classpath*:/spring-context-80-BlazeDS.xml
/WEB-INF/applicationContext*.xml
</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Map all /messagbroker requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>SpringMVCDispatcherServlet</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>

3,修改/WEB-INF/flex/services-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<!-- 注册SpringFactory工厂 -->
<factories>
<factory id="my-flexfactory4spring" class="com.ria.common.flex.spring.FlexSpringFactory"/>
</factories>
<services>
<service-include file-path="remoting-config.xml" />
<service-include file-path="proxy-config.xml" />
<service-include file-path="messaging-config.xml" />
<!-- 下面这个设置很重要,是应用的(全局的)参数,否则spring+blazeDS整合没法用. Application level default channels. Application level default channels are
necessary when a dynamic destination is being used by a service component
and no ChannelSet has been defined for the service component. In that case,
application level default channels will be used to contact the destination.
-->
<default-channels>
<channel ref="my-amf"/>
</default-channels>
</services>

<security>
<login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>
<!-- Uncomment the correct app server
<login-command class="flex.messaging.security.TomcatLoginCommand" server="JBoss">
<login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>
<login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/>
<login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/>
-->

<!--
<security-constraint id="basic-read-access">
<auth-method>Basic</auth-method>
<roles>
<role>guests</role>
<role>accountants</role>
<role>employees</role>
<role>managers</role>
</roles>
</security-constraint>
-->
</security>

<channels>
<!-- 以下的 spring_messagebroker 串正好是 web.xml里面的拦截URL串,以前是messagebroker,被 blazeds servlet拦截,现在是被spring+BlazeDS servlet拦截 -->
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<!--endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/-->
<endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled><!-- 这个是干嘛的? -->
</properties>
</channel-definition>


<channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
<!--endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/-->
<endpoint url="https://{server.name}:{server.port}/{context.root}/spring/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition>

<channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
<!--endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/-->
<endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>true</polling-enabled>
<polling-interval-seconds>4</polling-interval-seconds>
</properties>
</channel-definition>

<!-- copy from lcds -->
<channel-definition id="my-streaming-amf" class="mx.messaging.channels.StreamingAMFChannel">
<!--endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/streamingamf" class="flex.messaging.endpoints.StreamingAMFEndpoint"/-->
<endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/streamingamf" class="flex.messaging.endpoints.StreamingAMFEndpoint"/>
<properties>
<!-- 解决Streaming HTTP 在IE8下不能正常工作 -->
<max-streaming-clients>10</max-streaming-clients>
</properties>
</channel-definition>

<channel-definition id="my-http" class="mx.messaging.channels.HTTPChannel">
<!--endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/-->
<endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/>
</channel-definition>

<channel-definition id="my-secure-http" class="mx.messaging.channels.SecureHTTPChannel">
<!--endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/-->
<endpoint url="https://{server.name}:{server.port}/{context.root}/spring/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition>

</channels>

<logging>
<target class="flex.messaging.log.ConsoleTarget" level="Debug">
<properties>
<prefix>[BlazeDS] </prefix>
<includeDate>false</includeDate>
<includeTime>false</includeTime>
<includeLevel>false</includeLevel>
<includeCategory>false</includeCategory>
</properties>
<filters>
<pattern>Endpoint.*</pattern>
<pattern>Service.*</pattern>
<pattern>Configuration</pattern>
</filters>
</target>
</logging>

<system>
<redeploy>
<enabled>false</enabled>
<!--
<watch-interval>20</watch-interval>
<watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
<watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file>
<watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>
<watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file>
<watch-file>{context.root}/WEB-INF/flex/data-management-config.xml</watch-file>
<touch-file>{context.root}/WEB-INF/web.xml</touch-file>
-->
</redeploy>
</system>

</services-config>


4,修改/WEB-INF/flex/remoting-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
class="flex.messaging.services.RemotingService">

<adapters>
<adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>

<default-channels>
<channel ref="my-amf"/>
</default-channels>
<!-- flex spring service在这里注入,flex调用如下:
<mx:RemoteObject id="srv" destination="productService"/>
<mx:Button label="Update" click="srv.updateProduct(product)"/>
下面意思是说flex客服端在调用id为"productService" destination 的时候,
在spring工厂中寻找id为productDAOBean的bean。
其中:channels="my-amf"可以不要,因为缺省的channel就是它。
-->
<destination id="commonService" channels="my-amf">
<properties>
<!-- 这里指向service-config.xml里定义的工厂id -->
<factory>my-flexfactory4spring</factory>
<!-- 这里定义了spring的bean name -->
<source>flex_base_service</source>
</properties>
</destination>

</service>


注意点,就这些.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值