hessian(远程调用接口) 项目一

jar包依赖


        <!--远程接口依赖-->
        <!-- https://mvnrepository.com/artifact/com.caucho/hessian -->
        <dependency>
            <groupId>com.caucho</groupId>
            <artifactId>hessian</artifactId>
            <version>4.0.51</version>
        </dependency>


远程模拟:(没大用)

被连接的

<!--远程调用接口-->
  <servlet>
    <servlet-name>hessian</servlet-name>
    <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
    <init-param>
      <param-name>home-class</param-name>
      <param-value>com.test.PersonServiceImpl</param-value>
    </init-param>
    <init-param>
      <param-name>home-api</param-name>
      <param-value>com.test.PersonServciceI</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>hessian</servlet-name>
    <url-pattern>/hessian</url-pattern>
  </servlet-mapping>

见一个测试类: 对象不对 自己调整。

连接测试:

   HessianProxyFactory factory = new HessianProxyFactory();

        CustomerService service = (CustomerService) factory.create(CustomerService.class,"http://localhost:8080/remoting/customer");

        List<Customer> list = service.findnoassociationCustomers();

        System.out.println(list);

远程项目:要有上边的jar包
在这里插入图片描述一。建好pojo类 和接口 如上图:要和上一个项目包名类名一致

  二。配置远程服务的代理对象:其实就是创建  customerService  Bean  ,将接口实现类拿过来。

(在SpringMVC中配置)

<bean id="customerService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
		<!-- 注入接口类型 -->
		<property name="serviceInterface" value="com.gyf.crm.service.CustomerService"/>
		<!-- 服务访问路径 -->
		<property name="serviceUrl" value="http://localhost:8080/remoting/customer"/>
	</bean>

被连接的项目:
在web.xml中配置


	<servlet>
		<servlet-name>remoting</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>remoting</servlet-name>
		<url-pattern>/remoting/*</url-pattern>
	</servlet-mapping>

	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>

在remoting-servlet.xml 配置 (在web info 下)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx.xsd">
	<!-- 业务类  -->
	<bean id="customerService" class="com.gyf.crm.service.impl.CustomerServiceImpl" />
	
	<!-- 注册hessian服务 -->
	<bean id="/customer" class="org.springframework.remoting.caucho.HessianServiceExporter">
		<!-- 业务接口实现类 -->
		<property name="service" ref="customerService" />
		<!-- 业务接口 -->
		<property name="serviceInterface" value="com.gyf.crm.service.CustomerService" />
	</bean>
</beans>	
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值