首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

FLEX BlazeDS+Spring+Hibernate 配置顺利(结合自己公司框架)

2013-09-09 
FLEX BlazeDS+Spring+Hibernate 配置成功(结合自己公司框架)参考:http://yuqun888666.blog.163.com/blog/s

FLEX BlazeDS+Spring+Hibernate 配置成功(结合自己公司框架)

参考:http://yuqun888666.blog.163.com/blog/static/7917526720105301132396/

?

?

根据网上资料整理,部分有自己加入,但更想通过SSH2+BLAZEDS的结合方式来操作,如果谁有好的方式请留言,本人基本每天都会上博客。谢谢!看不懂得也可留言,共同学习 共同进步!

因为是结合自己公司的框架,不多做Spring+Hibernate配置介绍,主要介绍怎样结合

1.web.xml:

(1).将BlazeDS的web.xml内容删掉说明和welcom的部分加到工程的web.xml具体代码一起增加;

(2).配置Hibernate的hibernateFilter为了Hibernate的懒加载到达WEB层的时候也可以继续使用。

.<!--Hibernate Open Session in View Filter-->
?<filter>
??<filter-name>hibernateFilter</filter-name>
??<filter-class>
???org.springframework.orm.hibernate3.support.OpenSessionInViewFilter?
??</filter-class>
?</filter>

<filter-mapping>
??<filter-name>hibernateFilter</filter-name>
??<url-pattern>/*</url-pattern>
?</filter-mapping>

(3).将spring的application引入,在这里不多做说明。具体配置代码粘贴如下

=============================================================================

2.SpringFactory.java文件? 支持remote用到的

SpringFactory.java文件
package flex.samples.factories;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import flex.messaging.FactoryInstance;
import flex.messaging.FlexFactory;
import flex.messaging.config.ConfigMap;
import flex.messaging.services.ServiceException;
public class SpringFactory implements FlexFactory
{
????private static final String SOURCE = "source";
????public void initialize(String id, ConfigMap configMap) {}
????public FactoryInstance createFactoryInstance(String id, ConfigMap properties)
????{
????????SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties);
????????instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId()));
????????return instance;
????}
????public Object lookup(FactoryInstance inst)
????{
????????SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst;
????????return factoryInstance.lookup();
????}
????static class SpringFactoryInstance extends FactoryInstance
????{
????????SpringFactoryInstance(SpringFactory factory, String id, ConfigMap properties)
????????{
????????????super(factory, id, properties);
????????}
????????public String toString()
????????{
????????????return "SpringFactory instance for id=" + getId() + " source=" + getSource() + " scope=" + getScope();
????????}
????????public Object lookup()
????????{
????????????ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext());
????????????String beanName = getSource();
????????????try
????????????{
????????????????return appContext.getBean(beanName);
????????????}
????????????catch (NoSuchBeanDefinitionException nexc)
????????????{
????????????????ServiceException e = new ServiceException();
????????????????String msg = "Spring service named '" + beanName + "' does not exist.";
????????????????e.setMessage(msg);
????????????????e.setRootCause(nexc);
????????????????e.setDetails(msg);
????????????????e.setCode("Server.Processing");
????????????????throw e;
????????????}
????????????catch (BeansException bexc)
????????????{
????????????????ServiceException e = new ServiceException();
????????????????String msg = "Unable to create Spring service named '" + beanName + "' ";
????????????????e.setMessage(msg);
????????????????e.setRootCause(bexc);
????????????????e.setDetails(msg);
????????????????e.setCode("Server.Processing");
????????????????throw e;
????????????}
????????}???????
????}
}

=========================================================================================

3.services-config.xml:
????<factories>
??????<factory id="spring" />
????</factories>

=========================================================================================

4.SpringTest.java

package flex.samples;

public class SpringTest {

??? private String description;

??? public String getDescription() {
????????????? ?return "This description from String. [" + description + "]";
????????? ?}

??? public void setDescription(String description) {
??????????????? this.description = description;
??????????? }
?????? }

======================================================================================5.applicationContext.xml

?<bean id="springTest" style="line-height: 22px;">

remoting-config.xml:
<destination id="TestSpring">
????????<properties>
????????????<factory>spring</factory>??????? <service-config>
????????????<source>springTest</source> <!--此处注入IOC注入-->
????????</properties>
????</destination>


?

7.

Flex.mxml:

<mx:RemoteObject id="myspring" destination="TestSpring" />
<mx:Button x="25" y="80" label="Call Spring" width="100" click="myspring.getDescription();" />
<mx:Label x="25" y="100" width="334" text="{myspring.getDescription.lastResult}"/>

根据网上资料整理,部分有自己加入,但更想通过SSH2+BLAZEDS的结合方式来操作,如果谁有好的方式请留言,本人基本每天都会上博客。谢谢!

?

热点排行