SpringBoot整合Hessian

SpringBoot整合Hessian

Hessian是一个轻量级的Binary RPC(二进制远程调用协议)协议的remoting on http框架(远程调用框架),这个跟我们以前常用的webservice比较类似,但是Hessian比较轻量级。

需要的maven依赖

		<!--引入hessian-->
		<dependency>
			<groupId>com.caucho</groupId>
			<artifactId>hessian</artifactId>
			<version>4.0.38</version>
		</dependency>

1、服务端代码

1.1、业务接口

package com.msiwang.webservicedemo.service;

/**
 * @author : wangm
 * create at:  2020/9/18  9:18 AM
 * @description: 测试hessian  demo接口
 */
public interface HelloHessianService {

    /**
    * Discreption: 接口测试方法
    * @param: [name]
    * @return: java.lang.String
    * @author: wangm
    * @date: 2020/9/18 1:51 PM
    */
    String hello(String name);
}

1.2、服务端业务代码接口实现类

package com.msiwang.webservicedemo.service;

import org.springframework.stereotype.Service;

/**
 * @author : wangm
 * create at:  2020/9/18  9:19 AM
 * @description: 测试hessian  demo接口
 */
@Service
public class HelloHessianServiceImpl implements HelloHessianService {

    /**
     * Discreption: 接口测试方法
     * @param: [name]
     * @return: java.lang.String
     * @author: wangm
     * @date: 2020/9/18 1:51 PM
     */
    @Override
    public String hello(String name) {
        return "Hello Hessian "+name;
    }
}

1.3、服务端接口发布配置类,通过spirng的Configuration注解配置

package com.msiwang.webservicedemo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.caucho.HessianServiceExporter;

/**
 * @author : wangm
 * create at:  2020/9/18  1:47 PM
 * @description: hessian服务发布配置类
 */
@Configuration
public class HessianConfig {


    @Autowired
    private HelloHessianService helloHessianService;

    //发布服务
    @Bean(name = "/hessian")
    public HessianServiceExporter hessianServer() {
        HessianServiceExporter exporter = new HessianServiceExporter();
        exporter.setService(helloHessianService);
        exporter.setServiceInterface(HelloHessianService.class);
        return exporter;
    }
}

2、客户端调用代码

2.2、Application启动类

package com.msiwang.webserviceclient;

import com.msiwang.webserviceclient.service.HelloHessianService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.caucho.HessianProxyFactoryBean;

@SpringBootApplication
public class WebserviceClientApplication {

	@Bean
	public HessianProxyFactoryBean hessianClient() {
		HessianProxyFactoryBean hessianProxyFactoryBean = new HessianProxyFactoryBean();
		hessianProxyFactoryBean.setServiceUrl("http://localhost:8978/hessian");
		hessianProxyFactoryBean.setServiceInterface(HelloHessianService.class);
		return hessianProxyFactoryBean;
	}

	public static void main(String[] args) {
		SpringApplication.run(WebserviceClientApplication.class, args);
	}

}

2.2、客户端业务接口,这里跟服务端业务接口一致

package com.msiwang.webserviceclient.service;

/**
 * @author : wangm
 * create at:  2020/9/18  9:18 AM
 * @description: 测试hessian  client接口
 */
public interface HelloHessianService {

    /**
    * Discreption: 接口测试方法
    * @param: [name]
    * @return: java.lang.String
    * @author: wangm
    * @date: 2020/9/18 1:51 PM
    */
    String hello(String name);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值