Flex+spring+hibernate+mysql+blaze DS框架搭建

阅读更多

 以前在项目中使用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" ?>
< 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 >
 
    
     < 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 >
 
 
    
 
 
     < 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
 
    
    
     
 
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家园

你可能感兴趣的:(it家园,spring,IT家园)