有几个主要步骤:
接口类与实现类省略:
接口:com.base.HttpinvokeInterface.java 接口方法:test()
实现类:com.impl.HttpinvokeService
1.Server端web.xml配置信息:
a:一种DispatcherServlet方式,需要在servlet-name配置的spring.xml文件名必须和该名称一致
<servlet>
<servlet-name>httpinvoke(名称必须与配置横杠前面文件名一样如:httpinvoke-servlet.xml,配置与web.xml在同一个目录)</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>httpinvoke</servlet-name>
<url-pattern>/ httpinvoke/*(调用定义接口地址入口)</url-pattern>
</servlet-mapping>
b:另外一种HttpRequestHandlerServlet方式,无需保持spring配置文件名和当前参数一致。确保servlet-name中和spring的bean name一致
<servlet>
<servlet-name>serviceBeanName</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>serviceBeanName</servlet-name>
<url-pattern>/ httpinvoke/serviceBeanName</url-pattern>
</servlet-mapping>
2.Server端Spring配置 httpinvoke-servlet.xml(1.a的配置对应的文件名,1.b 文件名无限制):
<?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="/httpinvokeService" //1.a方式配置
<bean name="serviceBeanName" //1.b方式配置
class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service">
<ref bean=" httpinvokeService"/>
</property>
<property name="serviceInterface">
<value>com.base.HttpinvokeInterface</value>
</property>
</bean>
<baan id="httpinvokeService" class="com.impl.HttpinvokeService">
</beans>
3.Client端Spring配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="httpinvokeService"
class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:9111/CMS/ httpinvoke/ httpinvokeServiceService" />
<!-- 服务器IP地址:端口号/项目名称/(Server端web.xml中配置的<url-pattern>入口)/(服务器端配置的bean的name属性<bean name="/httpinvokeService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">......</bean>)-->
<property name="serviceInterface" value="com.base. HttpinvokeInterface"/>
</bean>
</beans>
4.Client端测试:
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.base.HttpinvokeInterface
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring远程调用客户端配置.xml"); //读取配置文件
HttpinvokeInterface service = (HttpinvokeInterface)applicationContext.getBean("httpinvokeService"); //通过接口得到服务器信息
service.test(); //调用服务器端的方法
System.out.println("远程调用,测试成功!");
}
}
相关推荐
NULL 博文链接:https://snowolf.iteye.com/blog/703732
普通javaweb项目调用springCloud接口(超级实用,很详细)但是要注意的事一定要对springboot和springcloud的有所了解,不然的话你也是看不懂的,大家一起努力共同学习
本文来自程序猿,本文主要介绍了SpringCloud微服务下服务接口调试及管理,什么样方式可以让微服务的接口管理变得更加容易些,希望对您的学习有所帮助。我们知道在微服务架构下,软件系统会被拆分成很多个独立运行的...
springRMI接口实现
spring boot接口项目,集成了token验证,jsp页面的支持等等
{"code":200,"data":[{"age":12,"name":"12","sex":"男","username":"张三","userpassword":"123"},{"age":22,"name":"12","sex":"女","username":"李白","userpassword":"4576"}]}
使用了ApplicationContextAware接口,获取spring管理的bean; 多项目整合夸spring容器获取bean的实现方式。
基于java以及spring boot构建的接口工程,实现高效的线上部署及restful形式访问
利用spring如何实现接口限流 1.创建自定义注解 ** * 限流注解 */ @Inherited @Documented @Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @...
在网上找了很久的资料,接口已经跟客户对接,特编写了代码文档和附带jar包,并含其他网站的参考地址,注意jdk环境要1.6或以上版本
基于struts+hibernate+spring银行开发的接口小系统
基础接口项目(get post)基础接口项目基础接口项目基础接口项目基础接口项目基础接口项目基础接口项目基础接口项目
CXF整合spring实现SOAP接口开发
适合有spring框架的javaEE平台,出自spring的HttpInvokerServiceExporter导出器,依赖Spring.jar
主要为大家详细介绍了Spring MVC接口防数据篡改和重复提交,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
spring security http接口鉴权使用示范项目
主要给大家介绍了关于Spring Boot接口设计防篡改、防重放攻击的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Spring Boot具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
Spring各种回调接口[定义].pdf
CXF+spring+restful创建一个web的接口项目源代码,添加了restful实现的配置及jar包