Spring Remoting了解与使用
来源:互联网 发布:软件授权使用协议 编辑:程序博客网 时间:2024/06/06 00:10
HttpInvokerServiceExporter只是spring remoting的一种,还有HessianServiceExporter,BurlapServiceExporter
下面一个例子以HttpInvokerServiceExporter为例的综合应用
也可以参考http://www.javaeye.com/topic/417767这个帖子
1.JettyDaemon类的start方法
下面一个例子以HttpInvokerServiceExporter为例的综合应用
也可以参考http://www.javaeye.com/topic/417767这个帖子
1.JettyDaemon类的start方法
- server = new Server();
- final SelectChannelConnector connector = new SelectChannelConnector();
- connector.setReuseAddress(true);
- connector.setPort(port);
- server.addConnector(connector);
- WebAppContext webAppContext = new WebAppContext();
- webAppContext.setContextPath("/");
- ServletHolder sh = new ServletHolder();
- sh.setName("helloServlt");
- sh.setClassName(DispatcherServlet.class.getName());
- sh.setInitParameter("contextConfigLocation","classpath:applicationContext-mvc.xml");
- sh.setInitOrder(0);
- webAppContext.addServlet(sh, "*.sv");
- webAppContext.setDescriptor("web/WEB-INF/web.xml");
- webAppContext.setResourceBase("web");
- // webAppContext.setConfigurationDiscovered(true);
- webAppContext.setParentLoaderPriority(true);
- server.setHandler(webAppContext);
- // 保证在退出时能优雅的退出jetty服务
- // server.setStopAtShutdown(true);
- // 以下代码是关键
- webAppContext.setClassLoader(applicationContext.getClassLoader());
- XmlWebApplicationContext xmlWebAppContext = new XmlWebApplicationContext();
- xmlWebAppContext.setParent(applicationContext);
- xmlWebAppContext.setConfigLocations(new String[] { "classpath:applicationContext-mvc.xml" });
- xmlWebAppContext.setServletContext(webAppContext.getServletContext());
- xmlWebAppContext.refresh();
- webAppContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,xmlWebAppContext);
- server.start();
server = new Server(); final SelectChannelConnector connector = new SelectChannelConnector(); connector.setReuseAddress(true); connector.setPort(port); server.addConnector(connector); WebAppContext webAppContext = new WebAppContext(); webAppContext.setContextPath("/"); ServletHolder sh = new ServletHolder(); sh.setName("helloServlt"); sh.setClassName(DispatcherServlet.class.getName()); sh.setInitParameter("contextConfigLocation","classpath:applicationContext-mvc.xml"); sh.setInitOrder(0); webAppContext.addServlet(sh, "*.sv"); webAppContext.setDescriptor("web/WEB-INF/web.xml"); webAppContext.setResourceBase("web"); // webAppContext.setConfigurationDiscovered(true); webAppContext.setParentLoaderPriority(true); server.setHandler(webAppContext); // 保证在退出时能优雅的退出jetty服务 // server.setStopAtShutdown(true); // 以下代码是关键 webAppContext.setClassLoader(applicationContext.getClassLoader()); XmlWebApplicationContext xmlWebAppContext = new XmlWebApplicationContext(); xmlWebAppContext.setParent(applicationContext); xmlWebAppContext.setConfigLocations(new String[] { "classpath:applicationContext-mvc.xml" }); xmlWebAppContext.setServletContext(webAppContext.getServletContext()); xmlWebAppContext.refresh(); webAppContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,xmlWebAppContext); server.start();
2.服务器bean配置,没啥特别,就是让spring自动调用start方法和stop方法
- <bean id="webDaemon" class="com.taobao.monitor.pf.analyse.master.core.JettyDaemon"
- init-method="start" destroy-method="stop">
- <property name="port" value="${master.port}"></property>
- </bean>
- 3.applicationContext-mvc.xml
- <bean id="urlMapping"
- class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
- <property name="mappings">
- <props>
- <prop key="/task2slave.sv">task2slaveService</prop>
- </props>
- </property>
- </bean>
- <bean id="task2slaveService"
- class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
- <property name="service" ref="taskManager"/> <!--实现类-->
- <property name="serviceInterface"> <!--接口,需要提供给调用方-->
- <value>com.taobao.monitor.pf.analyse.inter.Task2Slave</value>
- </property>
- </bean>
<bean id="webDaemon" class="com.taobao.monitor.pf.analyse.master.core.JettyDaemon"init-method="start" destroy-method="stop"><property name="port" value="${master.port}"></property> </bean>3.applicationContext-mvc.xml <bean id="urlMapping"class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"><property name="mappings"><props><prop key="/task2slave.sv">task2slaveService</prop></props></property></bean><bean id="task2slaveService"class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"><property name="service" ref="taskManager"/> <!--实现类--><property name="serviceInterface"> <!--接口,需要提供给调用方--><value>com.taobao.monitor.pf.analyse.inter.Task2Slave</value></property></bean>
4.调用方配置,直接使用task2Slave实例即可
- <!-- spring http 远程调用 -->
- <bean id="httpInvokerRequestExecutor"
- class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor">
- <property
- name="httpClient">
- <bean
- class="org.apache.commons.httpclient.HttpClient">
- <property
- name="timeout"
- value="${http.timeout}" />
- <property
- name="httpConnectionManager">
- <ref
- bean="multiThreadedHttpConnectionManager" />
- </property>
- </bean>
- </property>
- </bean>
- <!-- 获取远程任务接口对象,用来请求需要的job和rule对象 -->
- <bean id="task2Slave"
- class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
- <property name="serviceUrl">
- <value>http://${master.ip}:${master.port}/task2slave.sv</value>
- </property>
- <property name="serviceInterface">
- <value>com.taobao.monitor.pf.analyse.inter.Task2Slave</value>
- </property>
- <property name="httpInvokerRequestExecutor" ref="httpInvokerRequestExecutor"/>
- </bean>
- Spring Remoting了解与使用
- Spring-remoting使用心得1-RMI
- 在Spring中使用Hessian Remoting技术。
- 在Spring中使用Hessian Remoting技术
- 在Spring中使用Hessian Remoting技
- 在Spring中使用Hessian Remoting技术
- spring:remoting
- Spring 了解 与 选择
- 在Spring中使用Hessian Remoting技术-------实例附件源码
- 使用spring-remoting,解决HessianProtocolException: expected string at 0x6d
- JNA了解与使用
- spring Remoting 实现分布式
- Spring remoting简单例子
- 使用Flash Remoting实现Flex与ColdFusion通信
- 使用Flash Remoting实现Flash与ColdFusion 通信
- 使用Fluorine实现Flash与.NET之间的Remoting通信
- 【Spring】——宏观了解与原理
- Postgresql了解、安装与使用
- Android基础类之BaseAdapter
- 软件工程导论——实验报告
- Initialization, Provisioning and Management of CPEs
- Flash在chrome下的调试
- 标准化的意义所在
- Spring Remoting了解与使用
- select * from A1,A2 where A1.a = A2.b
- 常用的Javascript设计模式(全懂,你出师了)
- linux中查看**软件安装目录
- Android framework层实现实现wifi无缝切换AP
- 数组的创建(matlab)
- 测试
- windows 7 下安装 oracle 11g r2 em
- 对cookie操作的时候遇到了一些的 删除、修改、查询不了问题,看来篇文章发现不错,抓一下