首页 > 代码库 > Spring Http Invoker
Spring Http Invoker
配置如下:
①web.xml配置
<servlet> <servlet-name>remote</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置该Servlet随应用启动时候启动 --> <load-on-startup>1</load-on-startup> </servlet> <!-- 配置DispatcherServlet映射的url --> <servlet-mapping> <servlet-name>remote</servlet-name> <url-pattern>/remoting/*</url-pattern> </servlet-mapping>
②client.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans default-lazy-init="true"> <bean id="sync.BackupSearchService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> <property name="serviceUrl" value=http://www.mamicode.com/"http://${juyuan.webservice.address}:${juyuan.webservice.port}/${juyuan.webservice.application}/remoting/backupSearchService"/>>③remote.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter" name="/backupSearchService"> <property name="service" ref="BackupSearchService"/> <property name="serviceInterface" value=http://www.mamicode.com/"com.juyuan.service.IBackupSearchService"/> >④SyncService
package com.juyuan.service.impl; import java.lang.reflect.Method; import java.util.Date; import com.juyuan.model.Alarms; import com.juyuan.model.AlarmsKeys; import com.juyuan.model.Logs; import com.juyuan.model.LogsKeys; import com.juyuan.service.IAlarmsService; import com.juyuan.service.ILogsService; import com.juyuan.support.AppCommon; import com.juyuan.support.AppContext; /** * add by LB 已屏蔽.若要开启同步请去掉execute里注释的代码. * @author LB * */ public class SyncService implements Runnable{ private Method method = null; private Object serviceObj = null; private Object[] paramArray = null; /** * 同步数据通用类 * @param serviceObj 服务对象. * @param methodName 待调用的服务方法. * @param paramTypes 参数的类类型数组. * @param paramArray 参数数组.(必须能够序列化) */ public SyncService(Object serviceObj,String methodName,Class<Object>[] paramTypes,Object[] paramArray){ try { this.serviceObj = serviceObj; this.paramArray = paramArray; method = serviceObj.getClass().getMethod(methodName, paramTypes ); } catch (Exception e) { } } public void run() { try { method.invoke(serviceObj,paramArray); } catch (Exception e) { e.printStackTrace(); } } /** * 执行同步 */ public void execute(){ new Thread(this).start(); } }⑤调用方式:
new SyncService(this.getSyncConditionService(),"saveSearchCondition",new Class[]{DefaultSearchCondition.class},new Object[]{entity}).execute();
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。