Flex+Spring配置
关键字: flex spring
flex拓扑图制作只是一个简单的例子,可以运行,只是简单的呈现部分,如果要实现具体的拓扑图的功能,需要连接数据库,这里只简单说说flex与spring的结合,有了spring,再与hibernate以及struts就简单多了。
1、首先是web.xml需要添加flex的配置,增加如下的内容:
2、在spring的配置文件中增加:
3、然后需要配置flex的配置文件,flex文件下有个services-config.xml,
增加:
其中类如下(通过网上查的)
4、本人做flex时是使用的直接调用java的运程类,以下都是按照这个配置的,还有一个webservice的方法,各位可以收集收集。
在flex文件夹下有个remoting-config.xml文件,需要增加:
这样topoMap可以在flex进行定义了,如下:
<mx:RemoteObject id="topo" destination="topoMap">
这样flex+spring配置即完成。
1、首先是web.xml需要添加flex的配置,增加如下的内容:
- <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>
- <init-param>
- <param-name>flex.write.path</param-name>
- <param-value>/WEB-INF/flex</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet>
- <servlet-name>FlexMxmlServlet</servlet-name>
- <display-name>MXML Processor</display-name>
- <description>Servlet wrapper for the Mxml Compiler</description>
- <servlet-class>flex.bootstrap.BootstrapServlet</servlet-class>
- <init-param>
- <param-name>servlet.class</param-name>
- <param-value>flex.webtier.server.j2ee.MxmlServlet</param-value>
- </init-param>
- <init-param>
- <param-name>webtier.configuration.file</param-name>
- <param-value>/WEB-INF/flex/flex-webtier-config.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet>
- <servlet-name>FlexSwfServlet</servlet-name>
- <display-name>SWF Retriever</display-name>
- <servlet-class>flex.bootstrap.BootstrapServlet</servlet-class>
- <init-param>
- <param-name>servlet.class</param-name>
- <param-value>flex.webtier.server.j2ee.SwfServlet</param-value>
- </init-param>
- <!-- SwfServlet must be initialized after MxmlServlet -->
- <load-on-startup>2</load-on-startup>
- </servlet>
- <servlet>
- <servlet-name>FlexForbiddenServlet</servlet-name>
- <display-name>Prevents access to *.as/*.swc files</display-name>
- <servlet-class>flex.bootstrap.BootstrapServlet</servlet-class>
- <init-param>
- <param-name>servlet.class</param-name>
- <param-value>flex.webtier.server.j2ee.ForbiddenServlet</param-value>
- </init-param>
- </servlet>
- <servlet>
- <servlet-name>FlexInternalServlet</servlet-name>
- <servlet-class>flex.bootstrap.BootstrapServlet</servlet-class>
- <init-param>
- <param-name>servlet.class</param-name>
- <param-value>flex.webtier.server.j2ee.filemanager.FileManagerServlet</param-value>
- </init-param>
- <load-on-startup>10</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>MessageBrokerServlet</servlet-name>
- <url-pattern>/messagebroker/*</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>FlexMxmlServlet</servlet-name>
- <url-pattern>*.mxml</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>FlexSwfServlet</servlet-name>
- <url-pattern>*.swf</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>FlexForbiddenServlet</servlet-name>
- <url-pattern>*.as</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>FlexForbiddenServlet</servlet-name>
- <url-pattern>*.swc</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>FlexInternalServlet</servlet-name>
- <url-pattern>/flex-internal/*</url-pattern>
- </servlet-mapping>
<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>
<init-param>
<param-name>flex.write.path</param-name>
<param-value>/WEB-INF/flex</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>FlexMxmlServlet</servlet-name>
<display-name>MXML Processor</display-name>
<description>Servlet wrapper for the Mxml Compiler</description>
<servlet-class>flex.bootstrap.BootstrapServlet</servlet-class>
<init-param>
<param-name>servlet.class</param-name>
<param-value>flex.webtier.server.j2ee.MxmlServlet</param-value>
</init-param>
<init-param>
<param-name>webtier.configuration.file</param-name>
<param-value>/WEB-INF/flex/flex-webtier-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>FlexSwfServlet</servlet-name>
<display-name>SWF Retriever</display-name>
<servlet-class>flex.bootstrap.BootstrapServlet</servlet-class>
<init-param>
<param-name>servlet.class</param-name>
<param-value>flex.webtier.server.j2ee.SwfServlet</param-value>
</init-param>
<!-- SwfServlet must be initialized after MxmlServlet -->
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>FlexForbiddenServlet</servlet-name>
<display-name>Prevents access to *.as/*.swc files</display-name>
<servlet-class>flex.bootstrap.BootstrapServlet</servlet-class>
<init-param>
<param-name>servlet.class</param-name>
<param-value>flex.webtier.server.j2ee.ForbiddenServlet</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>FlexInternalServlet</servlet-name>
<servlet-class>flex.bootstrap.BootstrapServlet</servlet-class>
<init-param>
<param-name>servlet.class</param-name>
<param-value>flex.webtier.server.j2ee.filemanager.FileManagerServlet</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FlexMxmlServlet</servlet-name>
<url-pattern>*.mxml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FlexSwfServlet</servlet-name>
<url-pattern>*.swf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FlexForbiddenServlet</servlet-name>
<url-pattern>*.as</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FlexForbiddenServlet</servlet-name>
<url-pattern>*.swc</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FlexInternalServlet</servlet-name>
<url-pattern>/flex-internal/*</url-pattern>
</servlet-mapping>
2、在spring的配置文件中增加:
- <bean id="topoMapViewService" parent="baseTransaction">
- <property name="target">
- <bean
- class="com.jeffrey.nms.service.impl.TopoServiceImpl"><!---这里的方法可以通过flex进行调用--->
- <property name="topoMapDao" ref="topoMapDao" />
- <property name="linkInfoDao" ref="linkInfoDao" />
- </bean>
- </property>
- </bean>
<bean id="topoMapViewService" parent="baseTransaction">
<property name="target">
<bean
class="com.jeffrey.nms.service.impl.TopoServiceImpl"><!---这里的方法可以通过flex进行调用--->
<property name="topoMapDao" ref="topoMapDao" />
<property name="linkInfoDao" ref="linkInfoDao" />
</bean>
</property>
</bean>
3、然后需要配置flex的配置文件,flex文件下有个services-config.xml,
增加:
- <factories>
- <factory id="spring" class="com.jeffrey.nms.web.topo.SpringFactory"/>
- </factories>
<factories>
<factory id="spring" class="com.jeffrey.nms.web.topo.SpringFactory"/>
</factories>
其中类如下(通过网上查的)
- package com.jeffrey.nms.web.topo;
- 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;
- } // end method createFactoryInstance()
- 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;
- }
- }
- }
- }
package com.jeffrey.nms.web.topo;
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;
} // end method createFactoryInstance()
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;
}
}
}
}
4、本人做flex时是使用的直接调用java的运程类,以下都是按照这个配置的,还有一个webservice的方法,各位可以收集收集。
在flex文件夹下有个remoting-config.xml文件,需要增加:
- <destination id="topoMap">
- <properties>
- <factory>spring</factory>
- <source>topoMapViewService</source>
- </properties>
- lt;/destination>
<destination id="topoMap">
<properties>
<factory>spring</factory>
<source>topoMapViewService</source>
</properties>
</destination>
这样topoMap可以在flex进行定义了,如下:
<mx:RemoteObject id="topo" destination="topoMap">
这样flex+spring配置即完成。