以前在项目中使用Flex+spring+hibernate+mysql+blaze DS作为系统框架,今天抽时间把这个框架的搭建步骤做一个说明,以便下次开发使用。
开发工具使用的eclipse +flashbuider插件版本,具体的安装方法,请参照我另一篇文章,flex+java环境搭建.
开发环境和项目创建好之后,就开始整合spring和flex。
首先,在web.xml中加上flex session的监听器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
<? 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 >xxx</ display-name >
< description >xxx</ description >
< context-param >
< param-name >webAppRootKey</ param-name >
< param-value >webapp.xxx</ param-value >
</ context-param >
< context-param >
< param-name >log4jConfigLocation</ param-name >
< param-value >classpath:log4j.properties</ param-value >
</ context-param >
<!-- Http Flex Session attribute and binding listener support -->
< listener >
< listener-class >flex.messaging.HttpFlexSession</ listener-class >
</ listener >
< listener >
< listener-class >org.springframework.web.util.Log4jConfigListener</ listener-class >
</ listener >
< servlet >
< servlet-name >MessageBrokerServlet</ servlet-name >
< servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class >
< init-param >
< param-name >contextConfigLocation</ param-name >
< param-value >/WEB-INF/applicationContext.xml</ param-value >
</ init-param >
< load-on-startup >1</ load-on-startup >
</ servlet >
<!-- MessageBroker Servlet
<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<display-name>MessageBrokerServlet</display-name>
<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
<init-param>
<param-name>services.configuration.file</param-name>
<param-value>/WEB-INF/flex/services-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
-->
< servlet >
< servlet-name >RDSDispatchServlet</ servlet-name >
< display-name >RDSDispatchServlet</ display-name >
< servlet-class >flex.rds.server.servlet.FrontEndServlet</ servlet-class >
< init-param >
< param-name >useAppserverSecurity</ param-name >
< param-value >false</ param-value >
</ init-param >
< init-param >
< param-name >messageBrokerId</ param-name >
< param-value >_messageBroker</ param-value >
</ init-param >
< load-on-startup >10</ load-on-startup >
</ servlet >
< servlet-mapping id = "RDS_DISPATCH_MAPPING" >
< servlet-name >RDSDispatchServlet</ servlet-name >
< url-pattern >/CFIDE/main/ide.cfm</ url-pattern >
</ servlet-mapping >
< servlet-mapping >
< servlet-name >MessageBrokerServlet</ servlet-name >
< url-pattern >/messagebroker/*</ url-pattern >
</ servlet-mapping >
< welcome-file-list >
< welcome-file >login.html</ welcome-file >
< welcome-file >login.htm</ welcome-file >
</ welcome-file-list >
< mime-mapping >
< extension >doc</ extension >
< mime-type >application/msword</ mime-type >
</ mime-mapping >
< mime-mapping >
< extension >xls</ extension >
< mime-type >application/msexcel</ mime-type >
</ mime-mapping >
< mime-mapping >
< extension >pdf</ extension >
< mime-type >application/pdf</ mime-type >
</ mime-mapping >
< mime-mapping >
< extension >zip</ extension >
< mime-type >application/zip</ mime-type >
</ mime-mapping >
< mime-mapping >
< extension >rar</ extension >
< mime-type >application/rar</ mime-type >
</ mime-mapping >
< mime-mapping >
< extension >txt</ extension >
< mime-type >application/txt</ mime-type >
</ mime-mapping >
< mime-mapping >
< extension >chm</ extension >
< mime-type >application/mshelp</ mime-type >
</ mime-mapping >
< mime-mapping >
< extension >mp3</ extension >
< mime-type >audio/x-mpeg</ mime-type >
</ mime-mapping >
<!-- for WebSphere deployment, please uncomment -->
<!--
<resource-ref>
<description>Flex Messaging WorkManager</description>
<res-ref-name>wm/MessagingWorkManager</res-ref-name>
<res-type>com.ibm.websphere.asynchbeans.WorkManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
-->
</ web-app >
|
整个web.xml文件内容如上,可以直接使用,里面具体内容不做描述,如有不明白地方,可以直接百度。
下面是spring的applicationContext.xml配置文件,包含数据库的配置,事物的配置,直接贴出整个文件源码。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
<? xml version = "1.0" encoding = "UTF-8" ?>
< beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:context = "http://www.springframework.org/schema/context"
xmlns:aop = "http://www.springframework.org/schema/aop"
xmlns:tx = "http://www.springframework.org/schema/tx"
xmlns:flex = "http://www.springframework.org/schema/flex"
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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
< context:annotation-config />
< context:component-scan base-package = "cn.ccb.yn.acms" />
< flex:message-broker >
< flex:exception-translator ref = "flexExcetiionTranslator" />
< flex:message-service default-channels = "my-amf" />
</ flex:message-broker >
< bean id = "flexExcetiionTranslator" class = "cn.wgy.common.util.FlexExcetiionTranslator" />
< bean id = "AppDataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method = "close" >
< property name = "driverClass" value = "${jdbc.driverClassName}" />
< property name = "jdbcUrl" value = "${jdbc.url}" />
< property name = "user" value = "${jdbc.username}" />
< property name = "password" value = "${jdbc.password}" />
< property name = "minPoolSize" value = "1" />
< property name = "maxPoolSize" value = "25" />
< property name = "maxIdleTime" value = "180" />
</ bean >
< context:property-placeholder location = "classpath:jdbc.properties" />
<!-- 读取数据库配置文件结束 -->
< bean id = "transactionManager"
class = "org.springframework.orm.hibernate3.HibernateTransactionManager" >
< property name = "sessionFactory" >
< ref bean = "sessionFactory" />
</ property >
< property name = "nestedTransactionAllowed" value = "true" ></ property >
</ bean >
< aop:config >
< aop:advisor id = "managerTx" pointcut = "execution(* cn.wgy..*.ucc.*.*(..))"
advice-ref = "txAdvice" order = "2" />
</ aop:config >
< tx:advice id = "txAdvice" transaction-manager = "transactionManager" >
< tx:attributes >
< tx:method name = "get*" read-only = "true" />
< tx:method name = "find*" read-only = "true" />
< tx:method name = "*" rollback-for = "BizException" />
</ tx:attributes >
</ tx:advice >
< bean id = "jdbcTemplate" class = "org.springframework.jdbc.core.JdbcTemplate" >
< property name = "dataSource" >
< ref bean = "AppDataSource" />
</ property >
</ bean >
< bean id = "hibernateTemplate" class = "org.springframework.orm.hibernate3.HibernateTemplate" >
< property name = "sessionFactory" >
< ref bean = "sessionFactory" />
</ property >
</ bean >
< bean id = "sessionFactory" name = "sessionFactory"
class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean"
abstract = "false" >
< property name = "mappingDirectoryLocations" >
< list >
< value >classpath:/cn/wgy/common/model/</ value >
</ list >
</ property >
< property name = "hibernateProperties" >
< props >
< prop key = "hibernate.dialect" >org.hibernate.dialect.MySQLDialect</ prop >
< prop key = "hibernate.show_sql" >true</ prop >
< prop key = "hibernate.generate_statistics" >true</ prop >
< prop key = "hibernate.cache.provider_class" >org.hibernate.cache.EhCacheProvider</ prop >
< prop key = "hibernate.cache.use_query_cache" >true</ prop >
< prop key = "hibernate.query.factory_class" >org.hibernate.hql.classic.ClassicQueryTranslatorFactory</ prop >
< prop key = "hibernate.hbm2ddl.auto" >update</ prop >
</ props >
</ property >
< property name = "eventListeners" >
< map >
< entry key = "merge" >
< bean class = "org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" abstract = "false" />
</ entry >
</ map >
</ property >
< property name = "dataSource" >
< ref bean = "AppDataSource" />
</ property >
</ bean >
</ beans >
|
数据库连接配置文件:
1
2
3
4
5
6
7
8
9
|
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306/acms?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull jdbc.username=root jdbc.password=ROOT # DBCP Pool settings jdbc.InitialSize=5 jdbc.MaxActive=10 jdbc.MaxIdle=5 jdbc.MaxWait=30000 |
java给flex提供接口类的写法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
package cn.wgy.test.ucc.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.stereotype.Service;
import cn.ccb.yn.acms.test.service.TestService;
import cn.ccb.yn.acms.test.ucc.TestUcc;
@Service @RemotingDestination public class TestUccImpl implements TestUcc{
@Autowired TestService testServiceImpl; public String getTest(){
return testServiceImpl.getTest();
} } |
TestUccImpl就是flex页面用到的接口。转自IT家园
相关推荐
Flex+blazeds实现与mySQL连接数据库
网上收集的一些Blaze+Spring整合资料.
blaze DS 是一个免费的,弄让flex 调用 jsp 对象的东西 。
NULL 博文链接:https://taomujian.iteye.com/blog/337508
一个简单的基于Flex4的工程,只是实现了前后台及数据库的联系,其他的都比较简单,只适合新手看看。刚刚用于我的毕业设计,上传上来玩玩。使用方法附录在里面了,希望能帮到大家
搭配flex4.6+blaze+java开发环境所用的jar包。
flex cairngorm框架入门的一个例子,后台处理采用java完成。 采用mysql数据库,数据库名test,需要自己创建数据表login
这是一个flex通过blaze服务器与java交互的例子。 测试环境: win7 MyEclipse8.5 Flash Builder4.5 将文件解压后放到tomcat的webapps目录下。在IE上输入http://localhost/flexweb/flex_client.html。
构建整合Hibernate,Spring和BlazeDS的Flex开发环境
这是一个关于如何使用Blaze使Java和Flex进行通信的示例,绝对原创。
Flex的Blaze.war,flex必不可缺少的东西!!很值得下载
flex_blaze_java整合视频,希望对大家有所帮助。
flex blazeDS开发使用手册,对于集成blaze开发很有用处。
BlazeDS实现Flex与Java通信
blaze
flex服务器技术Blaze DS,flex服务器技术Blaze DS
Blaze AI 是一款快速、高度可定制的强大通用敌人 AI 引擎,价格实惠!如果您想在游戏中加入任何类型的敌方 NPC,Blaze 将构建您选择的任何模型,并为您的游戏打造智能、逼真和具有挑战性的模型。它可以通过单击按钮...
blazeds之helloworld篇 最基础的实现amf通信 环境tomcat+flex builder+myeclipse
TI omap4470 Blaze 开发板原理图