myeclipse 中配置Flex + Spring + Hiberate + Struts

在 myeclipse 中配置Flex + Spring + Hiberate + Struts

1. web.xml 的配置

   <web-app>
<display-name>FLEX_J2EEDEMO</display-name>
<description>
Administration tools for monitoring and management
</description>
<context-param>
<param-name>flex.class.path</param-name>
<param-value>
/WEB-INF/flex/hotfixes,/WEB-INF/flex/jars
</param-value>
</context-param>
<!-- Http Flex Session attribute and binding listener support -->
<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>
<!-- 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>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
<!-- 添加spring -->
<servlet>
<servlet-name>SpringContextServlet</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- 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>

2. Spring , Hiberate , Struts 的配置参加一般J2EE 配置

3. 配置flex

   项目WEB-INF下建立flex文件夹,放置services-config.xml,remoting-config.xml。
  
   services-config.xml 内容如下: 
    <?xml version="1.0" encoding="UTF-8"?>
<services-config>

    <services>
       <service-include file-path="remoting-config.xml" />
    </services>
   
      <factories>
<factory id="spring" class="flex.samples.factories.SpringFactory"/>
</factories>
  
        <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"/>
            -->
       
        <!-- 
        If running the console on WebSphere with administrative security enabled uncomment this section.  Also,
        create a User Group called "console_administrator" and add any users that are allowed to use the console to this group.
        These users must also have at least one role that allows them to access MBeans under WebSphere security.  Finally,
        be sure to use the WebSphere login-command above. 
        <security-constraint id="console">
            <auth-method>Basic</auth-method>
            <roles>
                <role>console_administrator</role>
               </roles>
           </security-constraint>
           -->       
        </security>


    <channels>

        <channel-definition id="amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
            <properties>
                <polling-enabled>false</polling-enabled>
            </properties>
        </channel-definition>

    </channels>

    <logging>

        <!-- You may also use flex.messaging.log.ServletLogTarget -->
        <target class="flex.messaging.log.ConsoleTarget" level="Error">
            <properties>
                <prefix>[BlazeDS] </prefix>
                <includeDate>false</includeDate>
                <includeTime>false</includeTime>
                <includeLevel>true</includeLevel>
                <includeCategory>true</includeCategory>
            </properties>
            <filters>
                <pattern>Endpoint.*</pattern>
            </filters>
        </target>

    </logging>

    <system>
        <redeploy>
            <enabled>true</enabled>
            <watch-interval>20</watch-interval>
            <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
            <touch-file>{context.root}/WEB-INF/web.xml</touch-file>
        </redeploy>
    </system>

</services-config>

    remoting-config.xml内容如下

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

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

    <default-channels>
        <channel ref="amf"/>
    </default-channels>
   
    <!-- 定义名为userService的服务 ,从spring容器中获得-->
   <destination id="userService">

     <properties>
          <factory>spring</factory>
          <source>userService</source>
     </properties>

   </destination>

</service>


通过以上配置文件,可在.mxml中直接应用J2ee 中的 userService
如FLEX_LOGIN.mxml中登录应用,内容如下

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:rpc="com.adobe.fxstruts.rpc.*" layout="absolute" >
<mx:Script>
        <![CDATA[               
            import flash.events.Event;
            import mx.controls.Alert;
            import mx.utils.ArrayUtil;
            import mx.rpc.events.ResultEvent;
            import mx.controls.Alert;
            private var userObj:Object=new Object();
            public var userName:String="";

            private function reset():void{
               username.text="";
               password.text="";
            }
           
            private function sendKeyHandler(evt:KeyboardEvent):void
            {

            //Enter 键
                if (evt.keyCode == 13)
            {
               this.login();
               return ;
                   }
            }

            private function loginResult(result:Object):void
            {
            userObj=Object(result);
            if(userObj["userPwd"]==password.text){
               Alert.show(userObj["fullName"]+"登录成功!");
                   }else
            {
               Alert.show(username.text+"登录失败!");
            }      
            }
           
            private function login():void{
         
            if(username.text=="" || password.text=="" ){
            Alert.show("请输入用户名或密码!");
            }else{
                userObj = getData.getUserByCode(username.text);
                userName=username.text;
            }
            }
                         
      ]]>
    </mx:Script>
    
    <mx:Panel 
        height="75%" width="75%" layout="absolute"
        paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
    <mx:Label width="71" color="blue" text="用户名" fontSize="14" x="41" y="36"/>
    <mx:TextInput  width="148" height="20" id="username" maxChars="20" editable="true" cornerRadius="1" x="97" y="38"/>
    <mx:Label width="37" color="blue" text="密码" fontSize="14" x="41" y="76"/>
    <mx:TextInput  editable="true" width="148" height="20" id="password" cornerRadius="1" displayAsPassword="true" enabled="true" maxChars="20" x="97" y="78"  keyDown="sendKeyHandler(event)"/>
    <mx:Button label="登录" width="67" fontSize="12" x="58" y="118"  click="login()"/>
    <mx:Button label="取消" width="68" fontSize="12" x="154" y="118" click="reset()"/>
    </mx:Panel>
    <mx:RemoteObject id="getData" destination="userService">
<mx:method name="getUserByCode" result="loginResult(event.result)" fault="Alert.show(event.fault.faultString,'Error')"/>
    </mx:RemoteObject>
</mx:Application>




    

你可能感兴趣的:(spring,MyEclipse,struts,Flex,websphere)