也来做一个springside的flex登陆

之前看过Springside论坛里lanfanss 做过一个类似的,仔细研究了一番,自己学Flex也有些时候了,按捺不住也想做一个试试,我的这个和lanfanss 那个稍有些不同,当然后台部分用的还是由springside 3.1.2的archetype生成的项目骨架,copy-jar以后脱离maven构成,剥离了Struts2。lanfanss 大人用了graniteds和pureMVC,而我的这个用的是adobeLCDS的开源版BlazeDS, graniteds主要是对Hibernate的延迟加载有支持,BlazeDS是官方出的,用的人还是多一些,不过由于不支持延迟加载,如果直接将延迟加载关闭,那么由于AS3没有泛型这一说,从客户端传过来的集合是没有类型的,直接是一堆ASObject,没法儿用,还得转换,无奈只能把ManyToMany去掉,用SQL来查询关系表数据。Spring和BlazeDS的整合这块儿用了Spring最近的一个扩展项目,Spring-BlazeDS(其实选择BalzeDS的原因就是想用用这个,等一下大家会看到原因),Flex这边没有用pureMVC,而是用一个叫Swiz的Flex框架,看过08年的Flex 360大会视频的一定知道这个......好了不废话了,给大家看点儿实际的。
      后台部分就不说了,先来看Spring-BlazeDS的配置,导包org.springframework.flex-1.0.0.M2.jar,spring官网就有,maven仓库里搜不到,
web.xml加入,
        <servlet>
                <servlet-name>dispacther</servlet-name>
                <servlet-class>
                        org.springframework.web.servlet.DispatcherServlet
                </servlet-class>
                <init-param>
                        <param-name>contextConfigLocation</param-name>
                        <param-value>
                        </param-value>
                </init-param>
                <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
                <servlet-name>dispacther</servlet-name>
                <url-pattern>/messagebroker/*</url-pattern>
        </servlet-mapping>
相当于代替了BlazeDS的MessageBroker,resource里加入配置文件:
<?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:flex="http://www.springframework.org/schema/flex"
        xmlns:security="http://www.springframework.org/schema/security"
        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
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-2.0.4.xsd
           ">

        <flex:message-broker>       //使用spring的message Broker代替BlazeDS,
                <flex:secured>         //使用spring为BlazeDS提供的LoginCommand来登录,权限验证由spring security负责,Flex端可以直接用ChannelSet.login来登陆

                </flex:secured>
        </flex:message-broker>
        <security:global-method-security>                                                          //这里给出业务方法访问权限,代替原来的基于url的权限,权限我随便给的,大家自己根据需要改
                <security:protect-pointcut
                        expression="execution(* org.catablog.service.*.*Manager.*(..))"
                        access="A_VIEW_USER" />
        </security:global-method-security>
        <flex:remote-service service-id="userService" ref="userManager" />   //导出spring bean为amf distination
        <flex:remote-service service-id="roleService" ref="roleManager" />

</beans>

不需要修改remote-config.xml和service-config.xml,这也是Spring-balze提供的配置方式,Flex端的代码都差不多,源码我放到下边儿了(是我做了一半儿的一个项目,只包含用户身份验证的部分,用springside3.1.2的archetype生成的东西,跟直接用miniweb差不多,剥离了struts2,数据库脚本是mysql的),springside原有的jar我就删了,多出来的jar包我给了pom文件,里边儿都有,org.springframework.flex-1.0.0.M2.jar官方没给maven仓库,我把jar包附上了。
http://www.namipan.com/d/659545529a48e275a6c4b1b36d3ab47468d14e4502791600


你可能感兴趣的:(spring,maven,Hibernate,Flex,360)