读书人

Flex 调整Spring

发布时间: 2012-10-27 10:42:26 作者: rapoo

Flex 整合Spring
web.xml

view plaincopy to clipboardprint?
<?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>flex</display-name>
<description>LiveCycle Data Services Application</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-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

</web-app>
<?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>flex</display-name>
<description>LiveCycle Data Services Application</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-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

</web-app>

applicationContext.xml

view plaincopy to clipboardprint?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean name="weatherBean" />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean name="weatherBean" />
</beans>

WEB-INF/flex/services-config.xml

不要改动,只加上下面段代码

view plaincopy to clipboardprint?
<factories>
<factory id="spring"
/>
</factories>
<factories>
<factory id="spring"
/>
</factories>

WEB-INF/flex/remoting-config.xml

不要改动,只加上下面段代码

view plaincopy to clipboardprint?
<destination id="WeatherService">
<properties>
<factory>spring</factory>
<!--applicationContext.xml中bean的id-->
<source>weatherBean</source>
</properties>
</destination>
<destination id="WeatherService">
<properties>
<factory>spring</factory>
<!--applicationContext.xml中bean的id-->
<source>weatherBean</source>
</properties>
</destination>

Test.java

view plaincopy to clipboardprint?
package my;

import date.User;

public class Test {
public User say(User u) {
u.setName("跑了一圈"+u.getName());
return u;
}
}
package my;

import date.User;

public class Test {
public User say(User u) {
u.setName("跑了一圈"+u.getName());
return u;
}
}

User.java

view plaincopy to clipboardprint?
package date;

public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

}
package date;

public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

}

关键到来了:把flex_spring.zip下的factory/src下的所有文件拷贝到你项目中编写Java代码的目录下

下载地址:

官方下载地址

csdn下载地址(无需下载点)


下面就是mxml文件类容

flex.mxml

view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="800" height="600" xmlns:date="date.*">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import date.FlexUser;
private function cik():void{
var flexuser:FlexUser=new FlexUser();
flexuser.name=username.text;
tesclass.say(flexuser);
tesclass.addEventListener(ResultEvent.RESULT,binglistener);
}
private function binglistener(e:ResultEvent):void{
var userresult:FlexUser=(FlexUser)(e.result);
Alert.show(userresult.name);
}
]]>
</mx:Script>
<mx:RemoteObject id="tesclass" destination="WeatherService">
</mx:RemoteObject>
<mx:Button label="测试" click=" cik()" x="461" y="364">
</mx:Button>
<mx:Label x="291" y="204" text="姓名" />
<mx:TextInput x="349" y="202" id="username" />
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="800" height="600" xmlns:date="date.*">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import date.FlexUser;
private function cik():void{
var flexuser:FlexUser=new FlexUser();
flexuser.name=username.text;
tesclass.say(flexuser);
tesclass.addEventListener(ResultEvent.RESULT,binglistener);
}
private function binglistener(e:ResultEvent):void{
var userresult:FlexUser=(FlexUser)(e.result);
Alert.show(userresult.name);
}
]]>
</mx:Script>
<mx:RemoteObject id="tesclass" destination="WeatherService">
</mx:RemoteObject>
<mx:Button label="测试" click=" cik()" x="461" y="364">
</mx:Button>
<mx:Label x="291" y="204" text="姓名" />
<mx:TextInput x="349" y="202" id="username" />
</mx:Application>


flex_src/date/FlexUser.as

view plaincopy to clipboardprint?
package date
{
[RemoteClass(alias="date.User")]
public class FlexUser
{
public function FlexUser()
{
}
public var name:String;
}
}
package date
{
[RemoteClass(alias="date.User")]
public class FlexUser
{
public function FlexUser()
{
}
public var name:String;
}
}
到这里基本完成了。

读书人网 >flex

热点推荐