欢迎交流转载,请注明出处:http://www.cnblogs.com/shizhongtao/p/3490037.html

上一篇我只是简单实用blazeds创建了一个实例,大多数开发中,都是结合spring的spring BlazeDS Integration来进行开发。首先你要去官方网站上下载个jar包,我这里提供了我项目中的所有jar包的打包供你测试本示例实用,当然里面有很多多余jar包。项目中所有jar包地址(如地址问题,请联系博主)。

集成开始,当然你要创建一个web项目,然后配置web.xml如下,这个就多添加了个spring的servlet,来代替"flex.messaging.MessageBrokerServlet"这个servlet。

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
 3 <web-app>
 4 
 5     <display-name>BlazeDS Spring Integration Application</display-name>
 6     <description>BlazeDS Spring Integration Application</description>
 7     
 8     <!-- Http Flex Session attribute and binding listener support -->
 9     <listener>
10         <listener-class>flex.messaging.HttpFlexSession</listener-class>
11     </listener>
12 
13     <listener>
14         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
15     </listener>
16 
17     <!-- Spring Dispatcher Servlet -->   
18     <servlet>
19         <servlet-name>flex</servlet-name>
20         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
21         <init-param>
22         <param-name>contextConfigLocation</param-name>
23         <!-- 就是你项目中的‘applicationContext.xml’,作用一样 -->
24         <param-value>/WEB-INF/flex-servlet.xml</param-value>
25     </init-param>
26         <load-on-startup>1</load-on-startup>
27     </servlet>
28 
29     <servlet-mapping>
30         <servlet-name>flex</servlet-name>
31         <url-pattern>/messagebroker/*</url-pattern>
32      </servlet-mapping>
33 
34     <welcome-file-list>
35         <welcome-file>index.html</welcome-file>
36         <welcome-file>index.jsp</welcome-file>
37     </welcome-file-list>
38 
39 
40 </web-app>

 然后修改/WEB-INF/flex-servlet.xml这个配置文件,为了使用 Spring BlazeDS Integration 的 tag,增加命名空间flex。我还是文件内容全部贴上,说明写到注释里面吧。

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:flex="http://www.springframework.org/schema/flex"
 4     xmlns:context="http://www.springframework.org/schema/context"
 5      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6     xsi:schemaLocation="
 7         http://www.springframework.org/schema/beans
 8         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 9         http://www.springframework.org/schema/flex
10         http://www.springframework.org/schema/flex/spring-flex-1.5.xsd
11         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
12     
13     <context:component-scan base-package="com.bing">
14     </context:component-scan>
15     <!-- 请求路由给 MessageBroker -->
16      <flex:message-broker>
17         <flex:message-service default-channels="my-streaming-amf,my-longpolling-amf,my-polling-amf,my-amf" />
18     </flex:message-broker> 
19     <!--     <flex:message-broker />  -->
20     <!-- 定义 Bean,并用 remoting-destination tag 把它暴露给 Flex,因为我用了annotation的方式,所以下面的注解掉了 -->
21     <!-- <bean  />  
22     <flex:remoting-destination ref="myService" />   -->
23 </beans>

然后修改/WEB-INF/flex/services-config.xml这个配置文件,默认的话这个文件夹是有四个文件的(services-config.xml、remoting-config.xml、proxy-config.xml、messaging-config.xml),集成spring后,其他三个都没有什么用了,我删掉了。

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <services-config>
  3 
  4   <!--   <services>
  5         <service-include file-path="remoting-config.xml" />
  6         <service-include file-path="proxy-config.xml" />
  7         <service-include file-path="messaging-config.xml" />        
  8     </services> -->
  9      <services>
 10         <default-channels>
 11            <channel ref="my-amf"/>
 12         </default-channels>
 13     </services>
 14     <security>
 15         <login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>
 16         <!-- Uncomment the correct app server
 17         <login-command class="flex.messaging.security.TomcatLoginCommand" server="JBoss">
 18         <login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>        
 19         <login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/>
 20         <login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/>
 21         -->
 22 
 23         <!-- 
 24         <security-constraint >
 25             <auth-method>Basic</auth-method>
 26             <roles>
 27                 <role>guests</role>
 28                 <role>accountants</role>
 29                 <role>employees</role>
 30                 <role>managers</role>
 31             </roles>
 32         </security-constraint>
 33          -->
 34     </security>
 35 
 36     <channels>
 37 
 38         <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
 39             <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
 40         </channel-definition>
 41 
 42         <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
 43             <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
 44             <properties>
 45                 <add-no-cache-headers>false</add-no-cache-headers>
 46             </properties>
 47         </channel-definition>
 48 
 49         <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
 50             <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
 51             <properties>
 52                 <polling-enabled>true</polling-enabled>
 53                 <polling-interval-seconds>4</polling-interval-seconds>
 54             </properties>
 55         </channel-definition>
 56         <channel-definition id="my-longpolling-amf" class="mx.messaging.channels.AMFChannel">
 57             <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amflongpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
 58             <properties>
 59                 <polling-enabled>true</polling-enabled>
 60                 <polling-interval-seconds>5</polling-interval-seconds>
 61                 <wait-interval-millis>60000</wait-interval-millis>
 62                 <client-wait-interval-millis>1</client-wait-interval-millis>
 63                 <max-waiting-poll-requests>200</max-waiting-poll-requests>
 64             </properties>
 65         </channel-definition>   
 66         <channel-definition id="my-streaming-amf"  
 67             class="mx.messaging.channels.StreamingAMFChannel">  
 68             <endpoint  
 69                 url="http://{server.name}:{server.port}/{context.root}/messagebroker/streamingamf"  
 70                 class="flex.messaging.endpoints.StreamingAMFEndpoint" />  
 71             <properties>  
 72                 <idle-timeout-minutes>0</idle-timeout-minutes>  
 73                 <max-streaming-clients>100</max-streaming-clients>  
 74                 <server-to-client-heartbeat-millis>1000  
 75                 </server-to-client-heartbeat-millis>  
 76                 <user-agent-settings>  
 77                     <!--  
 78                         MSIE 5, 6, 7 default max number of permanent HTTP connections is  
 79                         2.  
 80                     -->  
 81                     <user-agent match-on="MSIE" kickstart-bytes="2048"  
 82                         max-streaming-connections-per-session="1" />  
 83                     <!-- MSIE 8 max number is 6. -->  
 84                     <user-agent match-on="MSIE 8" kickstart-bytes="2048"  
 85                         max-streaming-connections-per-session="5" />  
 86                     <!-- Firefox 1, 2 max number is 2. -->  
 87                     <user-agent match-on="Firefox" kickstart-bytes="2048"  
 88                         max-streaming-connections-per-session="1" />  
 89                     <!-- Firefox 3 max number is 6. -->  
 90                     <user-agent match-on="Firefox/3" kickstart-bytes="2048"  
 91                         max-streaming-connections-per-session="5" />  
 92                     <!-- Safari 3, 4 max number is 4. -->  
 93                     <user-agent match-on="Safari" kickstart-bytes="2048"  
 94                         max-streaming-connections-per-session="3" />  
 95                     <!-- Chrome 0, 1, 2 max number is 6. -->  
 96                     <user-agent match-on="Chrome" kickstart-bytes="2048"  
 97                         max-streaming-connections-per-session="5" />  
 98                     <!-- Opera 7, 9 max number is 4.-->  
 99                     <user-agent match-on="Opera" kickstart-bytes="2048"  
100                         max-streaming-connections-per-session="3" />  
101                     <!-- Opera 8 max number is 8. -->  
102                     <user-agent match-on="Opera 8" kickstart-bytes="2048"  
103                         max-streaming-connections-per-session="7" />  
104                     <!-- Opera 10 max number is 8. -->  
105                     <user-agent match-on="Opera 10" kickstart-bytes="2048"  
106                         max-streaming-connections-per-session="7" />  
107                 </user-agent-settings>  
108             </properties>  
109         </channel-definition> 
110         <!--
111         <channel-definition >
112             <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/>
113         </channel-definition>
114 
115         <channel-definition >
116             <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/>
117             <properties>
118                 <add-no-cache-headers>false</add-no-cache-headers>
119             </properties>
120         </channel-definition>
121         -->
122     </channels>
123 
124     <logging>
125         <target class="flex.messaging.log.ConsoleTarget" level="Error">
126             <properties>
127                 <prefix>[BlazeDS] </prefix>
128                 <includeDate>false</includeDate>
129                 <includeTime>false</includeTime>
130                 <includeLevel>false</includeLevel>
131                 <includeCategory>false</includeCategory>
132             </properties>
133             <filters>
134                 <pattern>Endpoint.*</pattern>
135                 <pattern>Service.*</pattern>
136                 <pattern>Configuration</pattern>
137             </filters>
138         </target>
139     </logging>
140 
141     <system>
142         <redeploy>
143             <enabled>false</enabled>
144             <!-- 
145             <watch-interval>20</watch-interval>
146             <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
147             <watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file>
148             <watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>
149             <watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file>
150             <watch-file>{context.root}/WEB-INF/flex/data-management-config.xml</watch-file>
151             <touch-file>{context.root}/WEB-INF/web.xml</touch-file>
152              -->
153         </redeploy>
154     </system>
155 
156 </services-config>
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
猜你喜欢
  • 2021-05-13
  • 2021-04-02
  • 2021-06-27
  • 2021-09-07
  • 2021-05-26
  • 2021-07-03
  • 2022-02-23
相关资源
相似解决方案